From 08ac1815b5dbe18a41d2265524a041383d4a2794 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 15 Nov 2020 06:37:34 +0300 Subject: feat: manage job status --- src/services/events/event.service.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/services') 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(); } -- cgit v1.2.3