diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-14 16:31:59 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-14 16:31:59 +0300 |
commit | 36465387454cdb797f886f732d40a70faa92cbad (patch) | |
tree | 28616bd04e3e98c5bd40e82b0c674a0ea9437357 /src/services/events/event.service.js | |
parent | 2a791b8999dc08824baf6787021d45df676b4088 (diff) | |
download | bsu-fantom-36465387454cdb797f886f732d40a70faa92cbad.tar.gz |
refactor: reuse Mongoose connection in Agenda
Diffstat (limited to 'src/services/events/event.service.js')
-rw-r--r-- | src/services/events/event.service.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/services/events/event.service.js b/src/services/events/event.service.js new file mode 100644 index 0000000..5c5bcff --- /dev/null +++ b/src/services/events/event.service.js @@ -0,0 +1,35 @@ +const Agenda = require('agenda'); +const { getConnection } = require('../../connectDb.js'); + + +class Events { + setup(app) { + this.collectionName = 'events'; + + const connection = getConnection(); + this.agenda = new Agenda(); + this.agenda.mongo( + connection.collection(this.collectionName).conn.db, + this.collectionName + ); + + this.defineJobs(); + + 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 }); + }; +} + + +module.exports = app => app.use('/events', new Events()); + |