Defining and managing background jobs in Orionjs
@orion-js/dogs
package, jobs provide a robust way to manage both recurring and event-driven background operations.
@Jobs()
decorator on a class and the job-specific decorators on methods:
@Jobs()
to mark it as a job controllercreateRecurrentJob
or createEventJob
with its specific decorator (@RecurrentJob
or @EventJob
)params
option@Inject(() => Service)
Option | Type | Description |
---|---|---|
runEvery | number | string | Milliseconds between runs or a string like ‘1d’, ‘4h’, etc. Ignored if getNextRun is provided. |
getNextRun | Function | Function returning a Date for the next execution. Takes precedence over runEvery . |
priority | number | Job priority. Higher numbers get executed first (default: 100). |
onError | Function | Called if the job fails. Can be used to retry or dismiss the job. |
onStale | Function | Called if the job locktime is expired. |
saveExecutionsFor | number | Time in milliseconds to keep job execution history (default: 1 week). Set to 0 to disable. |
resolve | Function | The function that contains the job’s logic. |
Option | Type | Description |
---|---|---|
params | Object | Schema | Schema for validating job parameters. |
onError | Function | Called if the job fails. Can be used to retry or dismiss the job. |
onStale | Function | Called if the job locktime is expired. |
saveExecutionsFor | number | Time in milliseconds to keep job execution history (default: 1 week). Set to 0 to disable. |
resolve | Function | The function that contains the job’s logic and receives validated params. |
resolve
function receives additional parameters: