Task-level hooks
You can attachbefore and after hooks to individual scheduled tasks using the .before() and .after() methods.
Before hooks
The.before() method registers a callback that executes before the scheduled task runs:
before hooks to a single schedule. They execute in the order they were registered:
After hooks
The.after() method registers a callback that executes after the scheduled task completes:
after hooks execute sequentially after the task completes:
Complete example
Here’s a practical example combining both hooks:Global scheduler hooks
The scheduler provides global hooks that execute when the scheduler worker starts.onStarting hook
TheonStarting callback executes when the scheduler worker is initializing, before any tasks are scheduled:
tag: The tag filter being used (e.g.,'default','reports')
onStarted hook
TheonStarted callback executes after all scheduled tasks have been registered and the worker is fully operational:
onBoot hook
TheonBoot callback executes during the scheduler’s boot phase, before commands are loaded:
Practical use cases
Logging and monitoring
Health checks and notifications
Error tracking
Task-level hooks (
before and after) execute for each task execution, while global hooks (onStarting, onStarted, onBoot) execute once when the scheduler worker starts.