summaryrefslogtreecommitdiff
path: root/src/services/events/event.service.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/events/event.service.js')
-rw-r--r--src/services/events/event.service.js27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js
index 4d87c6c..227480d 100644
--- a/src/services/events/event.service.js
+++ b/src/services/events/event.service.js
@@ -42,37 +42,14 @@ class Events extends Service {
this.stopAllJobs();
const events = await this.Model.findNextEvents();
- if (!events.length) this.log('No upcoming events.');
+ if (!events.length) console.log('WARNING: no upcoming events');
this.jobs = events.map(event => new CronJob(
event.schedule,
- () => this.run(event._id)
+ () => event.run(handleTestJob)
));
this.startAllJobs();
}
-
- log(message) {
- const dateOpts = { timeStyle: 'medium', dateStyle: 'short' };
- const timestamp = new Date().toLocaleString('en', dateOpts);
- return console.log(`[${timestamp}] ${message}`);
- }
-
- async run(id) {
- const event = await this.Model.findById(id);
- event.lastRunAt = new Date();
- event.setStatus('running')
-
- try {
- this.log(`Event ${event.name} started`)
- await handleTestJob(event);
- this.log(`Event ${event.name} ended`)
- } catch (error) {
- event.setStatus('failed')
- }
- if (event.status === 'running') {
- event.setStatus('complete')
- }
- }
}