Add 10-second test 2 health logger and /_cron/tick endpoint
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user