Fix scheduling same tasks

This commit is contained in:
Anton Vakhrushev 2020-04-19 21:38:42 +03:00
parent 972d3872d6
commit bfacfbf2fa

View File

@ -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);
}