From ae94313667b3abe257c0767439c6d3986ba0fde6 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 14 Nov 2020 17:21:21 +0300 Subject: feat: launch session on schedule for many users --- src/services/events/event.service.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/services') diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js index 5c5bcff..accd45d 100644 --- a/src/services/events/event.service.js +++ b/src/services/events/event.service.js @@ -1,11 +1,13 @@ const Agenda = require('agenda'); const { getConnection } = require('../../connectDb.js'); +const handleAttendClassJob = require('../../handlers'); class Events { setup(app) { this.collectionName = 'events'; + // Reuse mongoose connection const connection = getConnection(); this.agenda = new Agenda(); this.agenda.mongo( @@ -13,20 +15,14 @@ class Events { this.collectionName ); - this.defineJobs(); + // Define jobs + this.agenda.define('attend class', handleAttendClassJob); return this.agenda.start(); }; - defineJobs() { - this.agenda.define('attend class', async job => { - console.log('Running attend class job with attrs:'); - console.log(job.attrs); - }); - }; - async create(data, params) { - return this.agenda.schedule(data.date, 'attend class', { data }); + return this.agenda.schedule(data.date, 'attend class', data); }; } -- cgit v1.2.3