diff --git a/backend/src/index.ts b/backend/src/index.ts index 5e3aea0..405be4b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,6 +1,7 @@ import 'dotenv/config'; import cors from 'cors'; import express, { type NextFunction, type Request, type Response } from 'express'; +import cron from 'node-cron'; import { buildApiPath, getConfig } from './config'; import { TursoClient } from './lib/db'; import { createHealthRouter } from './routes/health'; @@ -18,12 +19,17 @@ const apiRoot = config.apiPrefix || '/'; app.use(apiRoot, createHealthRouter(config)); app.use(apiRoot, createTodosRouter(config, db)); -// 1. Background 10-second health check logger -setInterval(() => { - console.log('[Health Check] Sandbox is healthy at ' + new Date().toISOString()); -}, 10000); +// 1. Cron Job A: Runs every 3 minutes +cron.schedule('*/3 * * * *', () => { + console.log('[Cron A] Heartbeat executing every 3 minutes: ' + new Date().toISOString()); +}); -// 2. Cloud Run Cron Tick endpoint (No-op to wake up event loop) +// 2. Cron Job B: Runs every 10 minutes +cron.schedule('*/10 * * * *', () => { + console.log('[Cron B] Heartbeat executing every 10 minutes: ' + new Date().toISOString()); +}); + +// 3. Cloud Run Cron Tick endpoint (No-op to wake up event loop) app.post('/_cron/tick', (req, res) => { const authHeader = req.headers.authorization; if (!authHeader || authHeader !== 'Bearer ' + process.env.CRON_TOKEN) {