From: xangelo Date: Thu, 26 May 2022 17:21:05 +0000 (-0400) Subject: swap tick from delayed job to repeatable X-Git-Url: https://git.xangelo.ca/?p=browser-rts.git;a=commitdiff_plain;h=9ca3486edce89dba61c1b91df04d513237114559 swap tick from delayed job to repeatable --- 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); } - });