From c3b76d1b5d0f85deb9a52dbe516c665ab4de8c07 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 28 Nov 2020 01:21:41 +0300 Subject: fix: re-fetch event before running --- src/services/events/event.service.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/services/events/event.service.js') diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js index 227480d..f2185a6 100644 --- a/src/services/events/event.service.js +++ b/src/services/events/event.service.js @@ -45,11 +45,23 @@ class Events extends Service { if (!events.length) console.log('WARNING: no upcoming events'); this.jobs = events.map(event => new CronJob( event.schedule, - () => event.run(handleTestJob) + () => this.run(event._id) )); this.startAllJobs(); } + + async run(id) { + const event = await this.Model.findById(id); + + try { + event.start(); + await handleAttendClassJob(event); + return event.complete(); + } catch (error) { + event.fail(error); + } + } } -- cgit v1.2.3