diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-27 22:41:25 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-27 22:41:25 +0300 |
commit | 9f7115217c34732753102e044a94711400b5affc (patch) | |
tree | 364390decc2b093162ad740838c8add16d2955c7 /src/handlers/index.js | |
parent | 6a4e4402a52c6649f0ffb1c6a1e9183caaf6e313 (diff) | |
download | bsu-fantom-9f7115217c34732753102e044a94711400b5affc.tar.gz |
feat: use cron to schedule jobs
Diffstat (limited to 'src/handlers/index.js')
-rw-r--r-- | src/handlers/index.js | 16 |
1 files changed, 7 insertions, 9 deletions
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; |