2020-12-03 05:53:10 +03:00
|
|
|
const path = require('path');
|
2020-12-02 11:26:15 +03:00
|
|
|
const pWaitFor = require('p-wait-for');
|
2020-12-03 05:53:10 +03:00
|
|
|
const addSeconds = require('date-fns/addSeconds');
|
2020-12-02 11:26:15 +03:00
|
|
|
const JobManager = require('../../lib/job-manager');
|
|
|
|
|
2020-12-03 05:53:10 +03:00
|
|
|
const jobManager = new JobManager(console);
|
2020-12-02 11:26:15 +03:00
|
|
|
|
2020-12-03 05:53:10 +03:00
|
|
|
const isJobQueueEmpty = (bree) => {
|
|
|
|
return (Object.keys(bree.workers).length === 0)
|
|
|
|
&& (Object.keys(bree.intervals).length === 0)
|
|
|
|
&& (Object.keys(bree.timeouts).length === 0);
|
|
|
|
};
|
2020-12-02 11:26:15 +03:00
|
|
|
|
|
|
|
(async () => {
|
2020-12-03 05:53:10 +03:00
|
|
|
const dateInTenSeconds = addSeconds(new Date(), 10);
|
|
|
|
|
2021-01-07 05:17:38 +03:00
|
|
|
jobManager.addJob({
|
|
|
|
at: dateInTenSeconds,
|
|
|
|
job: path.resolve(__dirname, '../jobs/timed-job.js'),
|
|
|
|
data: {
|
|
|
|
ms: 2000
|
|
|
|
},
|
|
|
|
name: 'one-off-scheduled-job'
|
|
|
|
});
|
2020-12-02 11:26:15 +03:00
|
|
|
|
2020-12-03 05:53:10 +03:00
|
|
|
await pWaitFor(() => (isJobQueueEmpty(jobManager.bree)));
|
2020-12-02 11:26:15 +03:00
|
|
|
|
|
|
|
process.exit(0);
|
|
|
|
})();
|