-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Container from 'typedi'; | ||
import CronService from '../services/cron'; | ||
|
||
export default async () => { | ||
const cronService = Container.get(CronService); | ||
|
||
await cronService.bootTask(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Joi } from 'celebrate'; | ||
import cron_parser from 'cron-parser'; | ||
|
||
const validateSchedule = (value: string, helpers: any) => { | ||
if (value.startsWith('@once') || value.startsWith('@boot')) { | ||
return value; | ||
} | ||
|
||
try { | ||
if (cron_parser.parseExpression(value).hasNext()) { | ||
return value; | ||
} | ||
} catch (e) { | ||
return helpers.error('any.invalid'); | ||
} | ||
return helpers.error('any.invalid'); | ||
}; | ||
|
||
export const scheduleSchema = Joi.string() | ||
.required() | ||
.custom(validateSchedule) | ||
.messages({ | ||
'any.invalid': '无效的定时规则', | ||
'string.empty': '定时规则不能为空', | ||
}); | ||
|
||
export const commonCronSchema = { | ||
name: Joi.string().optional(), | ||
command: Joi.string().required(), | ||
schedule: scheduleSchema, | ||
labels: Joi.array().optional(), | ||
sub_id: Joi.number().optional().allow(null), | ||
extra_schedules: Joi.array().optional().allow(null), | ||
task_before: Joi.string().optional().allow('').allow(null), | ||
task_after: Joi.string().optional().allow('').allow(null), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.