From f80835332e748b94a67c2a4a189a0ec9279bfd50 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sun, 10 Nov 2024 14:59:52 -0500 Subject: [PATCH] Autoblast scheduler --- api/auto/autoBlastPairings.js | 80 +++++++++++----------- api/controllers/user/account/getProfile.js | 1 - 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/api/auto/autoBlastPairings.js b/api/auto/autoBlastPairings.js index 1d7d2d3..4032b7b 100644 --- a/api/auto/autoBlastPairings.js +++ b/api/auto/autoBlastPairings.js @@ -7,19 +7,23 @@ import { blastRoundPairing } from '../controllers/tab/round/blast.js'; const autoBlastRounds = async () => { const pendingQueues = await db.sequelize.query(` - select autoqueue.*, tourn.id tournId - from autoqueue, round, event, tourn - where (autoqueue.active_at < NOW() OR autoqueue.active_at IS NULL) - and autoqueue.tag IN ("blast", "publish", "blast_publish") - and autoqueue.round = round.id + select aq.id, aq.tag, aq.created_at, + round.id roundId, round.name, round.label, round.published, + event.tourn tournId, event.type eventType, event.abbr eventAbbr + from (autoqueue aq, round, event, tourn) + where (aq.active_at < NOW() OR aq.active_at IS NULL) + and aq.tag IN ("blast", "publish", "blast_publish") + and aq.round = round.id and round.event = event.id and event.tourn = tourn.id - order by created_at + order by aq.created_at `, { type: db.Sequelize.QueryTypes.SELECT, }); - await db.sequelize.query(` + const promises = []; + + const aq = db.sequelize.query(` delete autoqueue.* from autoqueue where (autoqueue.active_at < NOW() OR autoqueue.active_at IS NULL) @@ -28,79 +32,75 @@ const autoBlastRounds = async () => { type: db.Sequelize.QueryTypes.DELETE, }); - for await (const queue of pendingQueues) { + promises.push(aq); - const rounds = await db.sequelize.query(` - select - round.id, round.name, round.label, round.published, - event.tourn tournId, event.type eventType - from round, event - where round.id = :roundId - and round.event = event.id - `, { - replacements: { - roundId: queue.round, - }, - type: db.Sequelize.QueryTypes.SELECT, - }); - - if (rounds.length < 1) { - return; - } + pendingQueues.forEach( async (round) => { - const round = rounds.shift(); + // Set the round to publish and process the various dependencies + // thereof. - // Set the round to publish and process the various dependencies thereof. - if (queue.tag !== 'blast') { + if (round.tag !== 'blast') { if (round.published !== 1) { - await db.sequelize.query(` + + const publish = db.sequelize.query(` update round set published = 1 where round.id = :roundId `, { replacements: { - roundId: round.id, + roundId: round.roundId, }, type: db.Sequelize.QueryTypes.UPDATE, }); + + promises.push(publish); } if (round.eventType === 'debate') { // Docshare rooms - await shareRooms(round.id); + const share = shareRooms(round.roundId); + promises.push(share); } if (round.eventType === 'debate' || round.eventType === 'wsdc') { // Publish Flips - await scheduleFlips(round.id); + const flips = scheduleFlips(round.roundId); + promises.push(flips); } // Invalidate Caches if (process.env.NODE_ENV === 'production') { - await invalidateCache(round.tournId, round.id); + const production = invalidateCache(round.tournId, round.roundId); + promises.push(production); } } - if (queue.tag !== 'publish') { - + if (round.tag !== 'publish') { // Blast the round! BLAST IT! const req = { body: { - sender : queue.created_by, + sender : round.created_by, noResponse : true, - message : queue.message, + message : round.message, + }, + session : { + person : round.created_by, }, params: { - roundId: round.id, + roundId: round.roundId, tournId: round.tournId, }, db, }; const res = {}; - await blastRoundPairing.POST(req, res); + const blast = blastRoundPairing.POST(req, res); + promises.push(blast); } - } + + }); + + await Promise.all(promises); }; await autoBlastRounds(); diff --git a/api/controllers/user/account/getProfile.js b/api/controllers/user/account/getProfile.js index 29a7127..7bf6103 100644 --- a/api/controllers/user/account/getProfile.js +++ b/api/controllers/user/account/getProfile.js @@ -53,7 +53,6 @@ export const getProfile = { delete personData.password; personData.session = req.session; - return res.status(200).json(personData); }, };