Ghost/ghost/job-manager
Naz 67e664208a 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
2020-11-24 16:40:35 +13:00
..
lib 🐛 Fixed cron expression to read seconds parameter 2020-11-24 16:37:46 +13:00
test Changed scheduled jobs not run immediately after initialization 2020-11-23 14:24:24 +13:00
.eslintrc.js Added new job manager package 2020-08-11 21:17:52 +01:00
index.js Added new job manager package 2020-08-11 21:17:52 +01:00
LICENSE Added new job manager package 2020-08-11 21:17:52 +01:00
package.json Published new versions 2020-11-23 16:14:42 +13:00
README.md Added documentation about job scheduling 2020-11-24 16:40:35 +13:00

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

or

yarn add @tryghost/job-manager

Usage

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

This is a mono repository, managed with lerna.

Follow the instructions for the top-level repo.

  1. git clone this repo & cd into it as usual
  2. Run yarn to install top-level dependencies.

Run

  • yarn dev

Test

  • yarn lint run just eslint
  • yarn test run lint and tests

Copyright & License

Copyright (c) 2020 Ghost Foundation - Released under the MIT license.