mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Added documentation about job scheduling
refs https://github.com/TryGhost/Ghost/issues/12402 - Adds examples on how to queue regular "immediate" and reccuring "scheduled" jobs
This commit is contained in:
parent
c0cecd71fe
commit
67e664208a
@ -1,5 +1,7 @@
|
||||
# Job Manager
|
||||
|
||||
A manager for tasks that have to be performed asynchronously, optionally recurring, scheduled or one-off in their nature.
|
||||
|
||||
## Install
|
||||
|
||||
`npm install @tryghost/job-manager --save`
|
||||
@ -11,6 +13,31 @@ or
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const JobManager = require('@tryghost/job-manager');
|
||||
|
||||
const logging = {
|
||||
info: console.log,
|
||||
warn: console.log,
|
||||
error: console.error
|
||||
};
|
||||
|
||||
const jobManager = new JobManager(logging);
|
||||
|
||||
// register a job "function" with queued execution in parent event loop
|
||||
jobManager.addJob(printWord(word) => console.log(word), 'hello');
|
||||
|
||||
// register a job "module" with queued execution in parent even loop
|
||||
jobManager.addJob('./path/to/email-module.js', {email: 'send@here.com'});
|
||||
|
||||
// register recurring job which needs execution outside parent event loop
|
||||
jobManager.scheduleJob('every 5 minutes', './path/to/jobs/check-emails.js', {}, 'email-checker');
|
||||
|
||||
// register recurring job with cron syntax running every 5 minutes
|
||||
// job needs execution outside parent event loop
|
||||
// for cron builder check https://crontab.guru/ (first value is seconds)
|
||||
jobManager.scheduleJob('0 1/5 * * * *', './path/to/jobs/check-emails.js', {}, 'email-checker-cron');
|
||||
```
|
||||
|
||||
## Develop
|
||||
|
||||
@ -36,4 +63,4 @@ Follow the instructions for the top-level repo.
|
||||
|
||||
# Copyright & License
|
||||
|
||||
Copyright (c) 2020 Ghost Foundation - Released under the [MIT license](LICENSE).
|
||||
Copyright (c) 2020 Ghost Foundation - Released under the [MIT license](LICENSE).
|
||||
|
Loading…
Reference in New Issue
Block a user