From 9ca3486edce89dba61c1b91df04d513237114559 Mon Sep 17 00:00:00 2001 From: xangelo Date: Thu, 26 May 2022 13:21:05 -0400 Subject: [PATCH] swap tick from delayed job to repeatable --- src/api.ts | 4 ++++ src/tasks/task.ts | 2 +- src/tasks/tick.ts | 11 ++--------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/api.ts b/src/api.ts index 903c235..9fab0f4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -404,4 +404,8 @@ server.start(); tick.trigger({ lastTickAt: 0, lastTick: 0 +}, { + repeat: { + cron: '0 * * * *' + } }); diff --git a/src/tasks/task.ts b/src/tasks/task.ts index a39129f..9b524a8 100644 --- a/src/tasks/task.ts +++ b/src/tasks/task.ts @@ -22,4 +22,4 @@ export class Task { trigger(data: T, opts?: Bull.JobOptions) { this.queue.add(data, opts); } -} \ No newline at end of file +} diff --git a/src/tasks/tick.ts b/src/tasks/tick.ts index 0f4c3eb..345f5af 100644 --- a/src/tasks/tick.ts +++ b/src/tasks/tick.ts @@ -9,6 +9,7 @@ type Tick = { export const tick = new Task('tick', async (task, job) => { const nextTick = job.data.lastTick+1; + const start = Date.now(); // +population*1.1 is where we take into account farms for bonus food production let sql = `update cities set @@ -64,14 +65,6 @@ export const tick = new Task('tick', async (task, job) => { console.log(e); } finally { - const now = new Date(); - const nextTickAt = 60 - now.getMinutes(); - console.log(`Tick scheduled for ${nextTickAt}min`); - - task.trigger({ - lastTickAt: +now, - lastTick: nextTick - }, { delay: 60000 * nextTickAt}); + console.log('Tick complete', Date.now() - start); } - }); -- 2.25.1