diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-15 06:37:34 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-15 06:37:34 +0300 |
commit | 08ac1815b5dbe18a41d2265524a041383d4a2794 (patch) | |
tree | 0433c947b54456e73af50590262b3c1d22098299 | |
parent | 614d077effe59a6c84ddab5a797213cb7423b5e4 (diff) | |
download | bsu-fantom-08ac1815b5dbe18a41d2265524a041383d4a2794.tar.gz |
feat: manage job status
-rw-r--r-- | src/handlers/index.js | 2 | ||||
-rw-r--r-- | src/services/events/event.service.js | 20 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/handlers/index.js b/src/handlers/index.js index 658d8d9..09cd726 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -52,8 +52,6 @@ const handleJob = async job => { try { await Bluebird.map(participants, participant => handleJobAsUser(job, browser, participant)); - } catch (err) { - console.error(err); } finally { await browser.close(); } diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js index 235dc32..a8b0e72 100644 --- a/src/services/events/event.service.js +++ b/src/services/events/event.service.js @@ -22,9 +22,23 @@ class Events { // Logs - this.agenda.on('start', job => console.log(`Starting ${job.attrs.name} job`)); - this.agenda.on('complete', job => console.log(`Job ${job.attrs.name} finished`)); - this.agenda.on('fail', (err, job) => console.log(`Job failed with the error ${err}`)); + this.agenda.on('start', job => { + console.log(`Starting ${job.attrs.data.name} job`); + job.attrs.status = 'running'; + job.save(); + }); + this.agenda.on('complete', job => { + console.log(`Job ${job.attrs.data.name} finished`); + if (job.attrs.status === 'running') { + job.attrs.status = 'complete'; + job.save(); + } + }); + this.agenda.on('fail', (err, job) => { + console.log(`Job ${job.attrs.data.name} failed with the error ${err.message}`); + job.attrs.status = 'failed'; + job.save(); + }); return this.agenda.start(); } |