CronJobManager is a scheduled task manager provided by NocoBase based on cron. It allows plugins to register scheduled tasks on the server for periodically executing specific logic.
The CronJobParameters type definition is as follows (from cron):
| Parameter | Type | Description |
|---|---|---|
| cronTime | string | Date | DateTime | Scheduled task time expression. Supports standard cron expressions, for example 0 0 * * * means execute daily at 00:00. |
| onTick | function | Task main function. Will be triggered at the specified time. |
| onComplete | function | Executes when the task is stopped by job.stop() or after the onTick function completes. |
| timeZone | string | Specify the execution time zone (e.g., Asia/Shanghai). |
| context | any | Context when executing onTick. |
| runOnInit | boolean | Whether to execute once immediately on initialization. |
| utcOffset | string | number | Specify the time zone offset. |
| unrefTimeout | boolean | Controls whether the event loop stays active. |
| Expression | Meaning |
|---|---|
* * * * * | Execute every minute |
0 * * * * | Execute every hour |
0 0 * * * | Execute daily at 00:00 |
0 9 * * 1 | Execute every Monday at 09:00 |
*/10 * * * * | Execute every 10 minutes |
💡 You can use crontab.guru to help generate expressions.
Scheduled tasks start and stop along with the application. You generally don't need to manually start or stop them.