|
| 1 | +'use strict'; |
| 2 | +Object.defineProperty(exports, '__esModule', { value: true }); |
| 3 | +const diff_1 = require('./diff'); |
| 4 | +const config_1 = require('./config'); |
| 5 | +const pushSender_1 = require('./pushSender'); |
| 6 | +const store_1 = require('./store'); |
| 7 | +const wcifClient_1 = require('./wcifClient'); |
| 8 | +async function runOnce() { |
| 9 | + const config = (0, config_1.getNotifierServiceConfig)(); |
| 10 | + const store = await (0, store_1.readStore)(); |
| 11 | + for (const competitionId of config.competitionIds) { |
| 12 | + const wcif = await (0, wcifClient_1.fetchWcif)(competitionId, { |
| 13 | + apiBaseUrl: config.wcifApiBaseUrl, |
| 14 | + token: config.apiToken, |
| 15 | + }); |
| 16 | + const nextSnapshots = (0, diff_1.createAssignmentSnapshots)(wcif); |
| 17 | + const previousSnapshots = store.snapshots.filter( |
| 18 | + (snapshot) => snapshot.competitionId === competitionId, |
| 19 | + ); |
| 20 | + const jobs = (0, diff_1.buildNotificationJobs)({ previousSnapshots, nextSnapshots }).filter( |
| 21 | + (job) => !store.deliveredDedupeKeys.includes(job.dedupeKey), |
| 22 | + ); |
| 23 | + await (0, pushSender_1.sendPushNotifications)({ |
| 24 | + jobs, |
| 25 | + subscriptions: store.subscriptions, |
| 26 | + }); |
| 27 | + store.snapshots = [ |
| 28 | + ...store.snapshots.filter((snapshot) => snapshot.competitionId !== competitionId), |
| 29 | + ...nextSnapshots, |
| 30 | + ]; |
| 31 | + store.deliveredDedupeKeys.push(...jobs.map((job) => job.dedupeKey)); |
| 32 | + } |
| 33 | + await (0, store_1.saveStore)(store); |
| 34 | +} |
| 35 | +async function main() { |
| 36 | + const config = (0, config_1.getNotifierServiceConfig)(); |
| 37 | + await runOnce(); |
| 38 | + if (process.env.NOTIFIER_RUN_ONCE === 'true') { |
| 39 | + return; |
| 40 | + } |
| 41 | + setInterval(() => { |
| 42 | + void runOnce(); |
| 43 | + }, config.wcifPollIntervalMs); |
| 44 | +} |
| 45 | +void main(); |
0 commit comments