Repository navigation
Conversation
The analyser called /ping and /queue every 30 seconds, so the website, and through it the database, never went quiet long enough for Railway to sleep them. The analyser now waits while the queue is empty and only contacts the website when there is work: - /queue reports, via X-Analysis-Next-Due-Seconds, when the next app falls due on its own (a stale analysis, a retryable failure, an abandoned claim), from a query mirroring nextApp's conditions. - Queueing an app (the request form or queue-refetch) posts a bare "wake" to an ntfy topic (NTFY_TOPIC, optionally NTFY_TOKEN), which the idle analyser subscribes to. A lost wake-up only delays the analysis. - The analyser asks at least daily (MAX_IDLE_WAIT), and every /queue call records a check-in, stored in a new analyser_heartbeat row so a woken web process still knows the analyser is online. The separate /ping endpoint is removed and the online window widens to 26 hours. - curl retries transient failures for up to a minute, so requests survive the website waking up. Claude-Session: https://claude.ai/code/session_01Fi3H98SycMK13rrr8ySSU1
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #38 (polling back-off).
Why
The analyser called
/pingand/queueabout every 30 seconds. Railway only sleeps a service after 5–10 minutes without outbound traffic, and a request to the website also reaches Postgres, so neither ever slept. With this change, the analyser only contacts the website when there is work.What
/queuesays when the next app falls due. With the queue empty, it setsX-Analysis-Next-Due-Seconds: the earliest time an app becomes claimable without being queued (a stale analysis, a retryable failure, an abandoned claim).Apps.nextDueAtworks this out with the same conditions asnextApp. If nothing will ever fall due, the header is absent.scripts/queue-refetch.js --applypost a barewaketo an ntfy topic (lib/analyserWake.js). This is best effort, with a 3 s timeout, and never throws. An idle analyser subscribes to the topic withcurland resumes on the first message.since=replays a wake-up sent between the/queuecheck and the subscription.NTFY_TOPICmust be set on both sides; without it everything is inert.NTFY_TOKENis optional, so publishing isn't subject to ntfy.sh's per-IP limits for anonymous use.NTFY_SERVERallows self-hosting.wait_for_workinprocessQueue.sh). It waits until the next due time, a wake-up orMAX_IDLE_WAIT(default 24 h), whichever comes first.MIN_IDLE_WAIT(60 s). If ntfy is unreachable, the analyser still sleeps out the full wait./queuecall is retried afterQUEUE_RETRY_WAIT(300 s)./queue. Each/queuecall records a check-in in a new one-rowanalyser_heartbeattable (migration015). A woken web process reads it back once./pingis removed, and the online window widens from 1 h to 26 h: the daily check-in plus one analysis.Trade-off: if a wake-up is lost (ntfy down, rate-limited or not configured), a requested app waits until the next due time or until the daily check.
Rollout
openssl rand -hex 16. Set it asNTFY_TOPICon the Railway web service and inanalyser/.env. Optionally setNTFY_TOKENtoo.015runs on start.processQueue.shon the Pi and restart it. Until then, the old script's/pingcalls get 404s, and its/queuecalls still work and count as check-ins.Testing
npm test: 173/173 pass. New tests:test/analyserWake.test.js: topic validation, default and self-hosted servers, the token header, failures never throwing.test/analyserQueue.test.js: the due header (future, overdue, never, absent once claimed), heartbeat writes and the stored heartbeat being read once,/pingreturning 404, and the request form posting the wake-up.nextDueAtagainst Postgres 16 with all migrations applied. It returnednullon an empty table and found the earliest of a stale analysis, a retryable failure (non-retryable ignored) and an old-version abandoned claim. It agreed withnextApp: overdue exactly whennextAppclaimed, then the new claim's timeout.wait_for_workagainst a fake ntfy stream sending blank keepalive lines:MIN_IDLE_WAITwithout a topic;curlprocess behind.NTFY_TOKENexists.npm audit --omit=dev: 0 vulnerabilities.https://claude.ai/code/session_01Fi3H98SycMK13rrr8ySSU1
Generated by Claude Code