swap tick from delayed job to repeatable
authorxangelo <git@xangelo.ca>
Thu, 26 May 2022 17:21:05 +0000 (13:21 -0400)
committerxangelo <git@xangelo.ca>
Thu, 26 May 2022 17:21:05 +0000 (13:21 -0400)
src/api.ts
src/tasks/task.ts
src/tasks/tick.ts

index 903c2358b153934f557b08bcb96f3fffeb6b2fd3..9fab0f4a72f2eb1937b46e6df7dcec865ccf25f2 100644 (file)
@@ -404,4 +404,8 @@ server.start();
 tick.trigger({
   lastTickAt: 0,
   lastTick: 0
+}, {
+  repeat: {
+    cron: '0 * * * *'
+  }
 });
index a39129f68f34af442a4b2cb54c51829853fd5570..9b524a883f082ec06ecf58ba48a48717a49bf583 100644 (file)
@@ -22,4 +22,4 @@ export class Task<T> {
     trigger(data: T, opts?: Bull.JobOptions) {
         this.queue.add(data, opts);
     }
-}
\ No newline at end of file
+}
index 0f4c3ebea5b1494cad4c89f660624dd8e847d979..345f5af7e81f8e79ca6383bba3e5454416ba7f32 100644 (file)
@@ -9,6 +9,7 @@ type Tick = {
 export const tick = new Task<Tick>('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>('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);
        }
-
 });