| 1 | "use strict"; |
| 2 | import {proj} from "../proj"; |
| 3 | |
| 4 | async function loop() { |
| 5 | const poped = await proj.predis.blpop("queue", 5); |
| 6 | const task_desc_s = poped[1]; |
| 7 | let task_desc; |
| 8 | try { |
| 9 | task_desc = JSON.parse(task_desc_s); |
| 10 | } catch (e) { |
| 11 | console.exception(e); |
| 12 | } |
| 13 | console.info("got task "+task_desc.func); |
| 14 | const func = task_desc.func; |
| 15 | const args = task_desc.args; |
| 16 | if (typeof(proj.tasks[func])!="function") { |
| 17 | console.log(`task ${func} not found`); |
| 18 | process.exit(-1) |
| 19 | } |
| 20 | try { |
| 21 | await ((this.tasks[func])(...args)); |
| 22 | } catch (e) { |
| 23 | console.exception(e); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | export async function start() { |
| 28 | while(true) { |
| 29 | loop(); |
| 30 | } |
| 31 | } |