diff options
Diffstat (limited to 'src/handlers/index.js')
-rw-r--r-- | src/handlers/index.js | 80 |
1 files changed, 28 insertions, 52 deletions
diff --git a/src/handlers/index.js b/src/handlers/index.js index c50ef23..188547c 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -1,53 +1,29 @@ -const puppeteer = require('puppeteer'); -const attendConference = require('./attendConference.js'); -const { clickElementBySelector } = require('./utils.js'); - -const { - EDUFPMI_URL, - EDUFPMI_USERNAME, - EDUFPMI_PASSWORD, - COURSE_URL -} = process.env; - -puppeteer.launch({ headless: true }) - .then(async browser => { - const page = await browser.newPage(); - - // Login - await page.goto(EDUFPMI_URL, { waitUntil: 'domcontentloaded' }); - await page.type('input#username', EDUFPMI_USERNAME); - await page.type('input#password', EDUFPMI_PASSWORD); - await Promise.all([ - clickElementBySelector(page, 'button#loginbtn'), - page.waitForNavigation() - ]); - console.log(`Logged in as ${EDUFPMI_USERNAME}`); - - // Find the course - await page.goto(COURSE_URL); - await Promise.all([ - clickElementBySelector(page, 'li.bigbluebuttonbn a'), - page.waitForNavigation() // Wait until the next page loads - ]); - - // Launch the conference in a new tab - const conferencePagePromise = new Promise(resolve => browser.on( - 'targetcreated', - target => resolve(target.page()) - )); - await clickElementBySelector(page, 'input#join_button_input'); - const conferencePage = await conferencePagePromise; - - // Prepare onJoin callback - const fillAttendance = async () => { - await page.goBack(); - await clickElementBySelector(page, 'li.attendance a'); - // TODO: actually fill the attendance - console.log('Attendance filled'); - }; - - await attendConference(conferencePage, fillAttendance); - await browser.close(); - }) - .catch(e => console.log(e)); +const { Types } = require('mongoose'); +const Bluebird = require('bluebird'); +const UserModel = require('../services/users/user.model.js'); +const launchUserSession = require('./launchUserSession.js'); + + +const handleJobAsUser = async (job, user) => { + console.log(`Running job as ${user.username}`); + return launchUserSession(user); +}; + +const handleJob = async job => { + console.log('Running attend class job'); + const { data } = job.attrs; + + const participants = await UserModel.find({ + _id: { + $in: data.participantIds.map(Types.ObjectId) + } + }); + + console.log({ participants }) + + return Bluebird.map(participants, participant => handleJobAsUser(job, participant)); +}; + + +module.exports = handleJob; |