Ghost/ghost/job-manager/test/examples/scheduled-one-off.js
Naz 34411cfcc1 Improved documentation and job examples
refs  #122

- As job signature has changed in 3bca4f63b8 and documentation needed updates accordingly
2021-01-07 15:17:38 +13:00

30 lines
794 B
JavaScript

const path = require('path');
const pWaitFor = require('p-wait-for');
const addSeconds = require('date-fns/addSeconds');
const JobManager = require('../../lib/job-manager');
const jobManager = new JobManager(console);
const isJobQueueEmpty = (bree) => {
return (Object.keys(bree.workers).length === 0)
&& (Object.keys(bree.intervals).length === 0)
&& (Object.keys(bree.timeouts).length === 0);
};
(async () => {
const dateInTenSeconds = addSeconds(new Date(), 10);
jobManager.addJob({
at: dateInTenSeconds,
job: path.resolve(__dirname, '../jobs/timed-job.js'),
data: {
ms: 2000
},
name: 'one-off-scheduled-job'
});
await pWaitFor(() => (isJobQueueEmpty(jobManager.bree)));
process.exit(0);
})();