1 import { Task } from './task';
2 import { db } from '../lib/db';
9 export const tick = new Task<Tick>('tick', async (task, job) => {
11 const nextTick = job.data.lastTick+1;
13 // +population*1.1 is where we take into account farms for bonus food production
14 let sql = `update cities set
15 credits = credits + population * 2,
32 population + round(coalesce(food/food, 0) * population*0.08),
41 db.raw(`update ticks set current_tick = ${nextTick}, last_tick_at = ${Date.now()}`)
48 const now = new Date();
49 const nextTickAt = 60 - now.getMinutes();
50 console.log(`Tick scheduled for ${nextTickAt}min`);
55 }, { delay: 60000 * nextTickAt});