-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Updater] Use BullMQ to schedule student updates
- Loading branch information
1 parent
74bfcea
commit d016cec
Showing
3 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
module.exports = async job => {} | ||
const { postUpdate } = require('./postUpdate') | ||
const { update } = require('./updater') | ||
const { purgeByStudentNumber } = require('./updater/purge') | ||
|
||
const updateMsgHandler = async updateMsg => { | ||
// TODO: Remove the following line after postUpdate is implemented correctly (worker.js calculates the processing time more accurately) | ||
const startTime = new Date() | ||
await update(updateMsg) | ||
await postUpdate(updateMsg, startTime) | ||
} | ||
|
||
module.exports = async job => { | ||
switch (job.name) { | ||
case 'students': { | ||
const studentNumbers = job.data.map(student => student.student_number) | ||
const msgInUpdateFormat = { type: job.name, entityIds: job.data.map(student => student.id) } | ||
await purgeByStudentNumber(studentNumbers) | ||
await updateMsgHandler(msgInUpdateFormat) | ||
break | ||
} | ||
default: | ||
throw new Error(`Unknown job type: ${job.name}`) | ||
} | ||
} |