From 9f7115217c34732753102e044a94711400b5affc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 27 Nov 2020 22:41:25 +0300 Subject: feat: use cron to schedule jobs --- src/handlers/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/handlers') diff --git a/src/handlers/index.js b/src/handlers/index.js index 09cd726..2234b05 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -12,12 +12,12 @@ const { EDUFPMI_URL, NODE_ENV, HEADFUL } = process.env; const headless = NODE_ENV === 'production' || !HEADFUL; -const handleJobAsUser = async (job, browser, user) => { - console.log(`Running job as ${user.username}`); +const handleEventAsUser = async (event, browser, user) => { + console.log(`Running event as ${user.username}`); const browserContext = await browser.createIncognitoBrowserContext(); - const { conferenceId } = job.attrs.data; + const { conferenceId } = event; const conferenceUrl = `${EDUFPMI_URL}/mod/bigbluebuttonbn/view.php?id=${conferenceId}`; const page = await launchUserSession(user, browserContext); @@ -37,12 +37,10 @@ const handleJobAsUser = async (job, browser, user) => { await browserContext.close(); }; -const handleJob = async job => { - const { data } = job.attrs; - +const handleEvent = async event => { const participants = await UserModel.find({ username: { - $in: data.participants + $in: event.participants } }); @@ -51,12 +49,12 @@ const handleJob = async job => { const browser = await puppeteer.launch({ headless, args: ['--no-sandbox', '--incognito'] }); try { - await Bluebird.map(participants, participant => handleJobAsUser(job, browser, participant)); + await Bluebird.map(participants, participant => handleEventAsUser(event, browser, participant)); } finally { await browser.close(); } }; -module.exports = handleJob; +module.exports = handleEvent; -- cgit v1.2.3