Ghost/ghost/job-manager/test/examples/scheduled-one-off.js

25 lines
730 B
JavaScript
Raw Normal View History

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.scheduleJob(dateInTenSeconds, path.resolve(__dirname, '../jobs/timed-job.js'), {
ms: 2000
}, 'one-off-scheduled-job');
await pWaitFor(() => (isJobQueueEmpty(jobManager.bree)));
process.exit(0);
})();