From bfacfbf2fa67c56c36f7f986dd9f42eab1c5e10b Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sun, 19 Apr 2020 21:38:42 +0300 Subject: [PATCH] Fix scheduling same tasks --- src/Scheduler.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 57dc044..23b7a58 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -58,8 +58,17 @@ export class Scheduler { scheduleTask(name: string, args: Args, ts?: number | undefined): void { this.logger.log('PUSH TASK', name, args, ts); - this.taskQueue.push(name, args, ts || timestamp()); const villageId = args.villageId; + let insertedTs = ts; + if (villageId && !insertedTs) { + const tasks = this.taskQueue.seeItems(); + const sameNamePred = t => sameVillage(villageId, t.args) && t.name === name; + insertedTs = lastTaskTime(tasks, sameNamePred); + if (insertedTs) { + insertedTs += 1; + } + } + this.taskQueue.push(name, args, insertedTs || timestamp()); if (villageId) { this.reorderVillageTasks(villageId); }