Changed scheduled jobs not run immediately after initialization

refs https://github.com/breejs/bree/issues/50
This commit is contained in:
Naz 2020-11-23 14:24:24 +13:00
parent 295887dd24
commit f1ab1597e8
3 changed files with 10 additions and 5 deletions

View File

@ -4,7 +4,10 @@ const assemble = (when, job, data, name) => {
const breeJob = {
name: name,
// NOTE: both function and path syntaxes work with 'path' parameter
path: job
path: job,
// NOTE: avoids executing job immidiately after initialization
// can remove it when https://github.com/breejs/bree/issues/50 is fixed
timeout: false
};
if (data) {

View File

@ -22,11 +22,11 @@ async function shutdown(signal) {
}
(async () => {
jobManager.scheduleJob('every 10 days', path.resolve(__dirname, '../jobs/graceful.js'));
jobManager.scheduleJob('every 10 seconds', path.resolve(__dirname, '../jobs/graceful.js'));
await setTimeoutPromise(100); // allow job to get scheduled
await pWaitFor(() => Object.keys(jobManager.bree.workers).length === 0);
await pWaitFor(() => (Object.keys(jobManager.bree.workers).length === 0) && (Object.keys(jobManager.bree.intervals).length === 0));
process.exit(0);
})();

View File

@ -100,11 +100,13 @@ describe('Job Manager', function () {
await delay(1); // let the job execution kick in
should(Object.keys(jobManager.bree.workers).length).equal(1);
should(Object.keys(jobManager.bree.workers).length).equal(0);
should(Object.keys(jobManager.bree.timeouts).length).equal(0);
should(Object.keys(jobManager.bree.intervals).length).equal(1);
await jobManager.shutdown();
should(Object.keys(jobManager.bree.workers).length).equal(0);
should(Object.keys(jobManager.bree.intervals).length).equal(0);
});
});
});