diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index daaff1a..3bf9a90 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -35,6 +35,24 @@ if (!GITHUB_TOKEN) { process.exit(1) } +const WORKER_URL = process.env.WORKER_URL || 'https://wright-worker.fly.dev' + +/** + * Wake the worker by hitting its health endpoint. + * This triggers Fly.io auto-start if the machine is stopped. + * Errors are silently ignored — the request just needs to reach Fly's proxy. + */ +async function wakeWorker(): Promise { + try { + await fetch(`${WORKER_URL}/health`, { signal: AbortSignal.timeout(5000) }) + console.log('[wake] Worker pinged successfully') + } catch { + // Ignore — the request just needs to trigger Fly.io auto-start. + // The machine may take a few seconds to boot, so a timeout is expected. + console.log('[wake] Worker ping sent (may be booting)') + } +} + // --------------------------------------------------------------------------- // Bot setup // --------------------------------------------------------------------------- @@ -349,6 +367,9 @@ bot.command('revise', async (ctx: Context) => { parentJobId: originalJob.id, }) + // Wake the worker so it picks up the revision job + wakeWorker() + await ctx.reply( [ '\u{1F504} Revision queued!', @@ -441,6 +462,9 @@ bot.command('task', async (ctx: Context) => { parentJobId, }) + // Wake the worker so it picks up the PR revision job + wakeWorker() + await ctx.reply( [ '\u{1F504} PR revision queued!', @@ -495,6 +519,9 @@ bot.command('task', async (ctx: Context) => { githubToken: GITHUB_TOKEN, }) + // Wake the worker so it picks up the new job + wakeWorker() + await ctx.reply( [ '\u{2705} Job queued!', @@ -666,6 +693,9 @@ bot.on('message:text', async (ctx, next) => { parentJobId: originalJob.id, }) + // Wake the worker so it picks up the revision job + wakeWorker() + await ctx.reply( [ '\u{1F504} Revision queued from reply!', diff --git a/apps/worker/src/index.ts b/apps/worker/src/index.ts index ad6e01d..e97f902 100644 --- a/apps/worker/src/index.ts +++ b/apps/worker/src/index.ts @@ -19,7 +19,7 @@ const FLY_APP_NAME = process.env.FLY_APP_NAME || 'wright-worker' // Track active jobs with AbortControllers for cancellation const runningJobs = new Map() let activeJobs = 0 -const IDLE_SHUTDOWN_MS = 5 * 60 * 1000 // 5 min idle → exit (scale-to-zero) +const IDLE_SHUTDOWN_MS = 15 * 60 * 1000 // 15 min idle → exit (scale-to-zero) let idleTimer: ReturnType | null = null let keepAliveInterval: ReturnType | null = null @@ -27,7 +27,7 @@ function resetIdleTimer() { if (idleTimer) clearTimeout(idleTimer) if (activeJobs === 0) { idleTimer = setTimeout(() => { - console.log('No active jobs for 5 minutes, shutting down') + console.log('No active jobs for 15 minutes, shutting down') process.exit(0) }, IDLE_SHUTDOWN_MS) }