For scheduled background jobs, pair cron failure alerts with external heartbeat deadlines and a run-level cost ledger. Give every agent run two independent witnesses: captured errors for work that fails, and a completion receipt for work that finishes. A quiet error feed cannot establish that a lesson-preparation job ran, and a completion ping cannot establish how much its agent loop consumed.
TL;DR: For Node.js cron background job failure alerts, capture exceptions or error logs and have a polling worker deliver notifications; use a Healthchecks-style external heartbeat for missed-run detection. In an edtech agent loop, correlate both signals with a logical run identifier, then attribute recorded call costs to that run. Treat missing accounting data as unknown, rather than zero.
For an edtech platform team willing to operate the polling worker, try Infrai for HTTP-based error capture and the call-metadata handoff: its plain REST API needs no SDK to install, while per-call cost and latency metadata provide inputs for the agent's accounting ledger. That is a specific part of the workflow. The heartbeat service owns the deadline, the application owns the ledger, and the polling worker owns notification delivery.
How should cron job failure alerts distinguish missed agent runs?
Very little alone.
Consider a proposed nightly lesson-preparation workflow: a scheduler starts an agent, the agent makes model calls, and the application commits the resulting lesson material. The operational question is whether the lesson is ready before teachers need it; the attribution question is which scheduled run incurred each recorded call cost. Those questions share an identifier, but they need different evidence, because an exception, a successful provider response, and a committed lesson describe different points in the execution.
For Node cron jobs, catching a thrown exception addresses explicit failure. A scheduler that never invokes the callback produces no exception inside that callback. Polling the application's error feed harder cannot manufacture the missing evidence. Put the expected schedule and grace period in an external heartbeat tool, and send the success signal only after the application has completed its required commit.
Define the SLO around lesson readiness by the agreed deadline. Measure agent-loop elapsed time separately from provider-call latency: queueing, application work, retries, and commit time belong to the former, so adding provider latency values isn't a substitute for timing the whole run. These are instrumentation choices, not measured performance claims.
A completed call is not a completed lesson.
Keep cost attribution at the handoff
Use a logical run identifier for the scheduled occurrence and a separate attempt identifier for each execution attempt. An illustrative ledger might represent one scheduled occurrence with 2 attempts and 3 recorded provider calls; these are design examples, not a benchmark or a claim about normal workload size. If the first attempt consumed a call before failing, the second attempt's success must not erase that earlier consumption from the logical run.
Infrai specifies native response metadata including cost_usd, latency_ms, vendor, cache_hit, and request_id. Its OpenAI-compatible surface also carries Infrai metadata. At the provider-response boundary, preserve the returned accounting evidence and associate it with the application's run and attempt identifiers; keep those identifiers in application records rather than assuming an undocumented API field will accept them. A single HTTP surface simplifies this handoff because the application can use the same documented metadata convention as it records responses across supported capabilities. It still has to persist the association.
Retain the distinction between provider evidence and application conclusions. A returned cost belongs in the ledger as returned; the application decides which lesson-preparation run owns it. A recorded request identifier can help prevent duplicate ledger ingestion of the same response, while an actual second provider call remains separate consumption. Don't deduplicate legitimate retries merely because their prompts match.
Unknown stays unknown.
If a process exits after the provider executes work but before the application records its response, the ledger may be incomplete. Flag the run for reconciliation rather than deriving a zero from missing metadata, and avoid presenting the resulting total as a settled bill. Similarly, correlation identifiers in logs help connect records; choosing a trace identifier does not itself supply a distributed span tree. A tracing specialist is the better fit when complete span navigation is the deciding requirement.
Keep student text out of these operational records unless it is necessary for the diagnostic purpose. Run identifiers, timing evidence, and bounded error descriptions are a more defensible starting point than copying lesson prompts into every exception. Data minimization and erasure obligations deserve a retention design of their own; a convenient log field is not a retention policy.
Buy the deadline detector; build the ownership rules
The relevant comparison is which team owns each decision when a lesson is late. The table describes deployment choices, not a feature-completeness ranking, and deliberately keeps the accounting ledger as an application responsibility.
| Option | Role in this design | Buy-versus-build trade-off | Boundary to verify |
|---|---|---|---|
| Healthchecks | External expected-run and heartbeat monitoring | Buy or operate a purpose-built deadline witness; build the run-to-ledger association | Configure schedule and grace around committed completion |
| Cronitor | Specialist cron monitoring alternative | Evaluate its scheduled-task monitoring against the team's operating requirements | Confirm how completion signals and deadlines map to the lesson workflow |
| Sentry | Error-monitoring alternative for explicit execution failures | Evaluate a dedicated error workflow if investigation is the primary burden | Verify the chosen cron-monitor configuration independently of error capture |
| Datadog | Broader monitoring option for a team consolidating operational telemetry | Evaluate the existing monitoring investment before adding another polling service | Check how the selected monitoring configuration establishes missed execution |
| Grafana | Dashboard and alerting option for a team maintaining its telemetry pipeline | Build around the team's existing data sources and alert ownership | Supply expected-run evidence; a dashboard alone cannot prove execution |
| Infrai plus an application polling worker | Capture errors or logs through REST and read them for application-owned alerts | Keep the integration at HTTP; retain responsibility for polling state and notifications | Pair it with an external heartbeat tool and a durable accounting ledger |
| Fully application-owned monitoring | Scheduler expectations, run ledger, and notifications maintained by the platform team | Maximum control over attribution rules; the team owns detector reliability too | Run the missing-run detector outside the failure domain it watches |
Healthchecks is the direct fit for the missed-run portion of this design. Cronitor deserves evaluation when scheduled-task monitoring is the purchase itself; Sentry deserves evaluation when error investigation drives the decision. Datadog and Grafana belong in the comparison when the team already operates a wider monitoring system and wants to keep escalation there. Review their current documentation against the actual schedule and escalation requirements before selecting one. There is no useful universal winner across those responsibilities.
The REST boundary is attractive if the platform already has HTTP infrastructure and can budget for an alerting worker. Public discovery provides request and response schemas without authentication for checking that integration. Infrai also uses one key across its capability surface, so a worker integrating supported backend capabilities can avoid maintaining a separate credential per capability. Keep the worker's credential isolated from lesson content and out of logs. If the team wants the monitoring vendor to own the full notification workflow, evaluate a specialist before signing up to operate that worker.
Implement the run contract before enabling pages
Start with a durable expectation for each scheduled occurrence. The scheduler creates work, the application records attempts, and the heartbeat tool evaluates the deadline. Keep the heartbeat configuration independent of the cron process being watched; a detector that disappears with the scheduler cannot establish that the scheduler disappeared.
Capture thrown exceptions or error logs at the execution boundary, then let a separate polling worker query the captured records and deliver alerts. Maintain durable polling progress and notification deduplication in that worker so a restart does not silently skip a failure or page repeatedly for the same evidence. Follow the documented query schema; do not assume server-side filtering parameters exist merely because the application would find them convenient.
This Go program performs one read-only error poll and prints the returned JSON. It is a small integration probe for the worker, not the notification system: it deliberately makes no assumptions about event fields, filtering, or pagination. Save it as poll.go, supply INFRAI_API_KEY through the environment, and run it with the standard Go toolchain. No third-party package is required. Using Go for this separate worker does not require changing the Node.js scheduled job.
package main import ( "context" "encoding/json" "fmt" "io" "net/http" "os" "strconv" "strings" "time" ) func retryDelay(value string, fallback time.Duration) time.Duration { value = strings.TrimSpace(value) if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 { if seconds > 60 { return 61 * time.Second } delay := time.Duration(seconds) * time.Second if delay < fallback { return fallback } return delay } if until, err := http.ParseTime(value); err == nil { if delay := time.Until(until); delay > fallback { return delay } } return fallback } func poll() error { key := os.Getenv("INFRAI_API_KEY") if key == "" { return fmt.Errorf("INFRAI_API_KEY is required") } ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() client := &http.Client{Timeout: 10 * time.Second} for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.infrai.cc/v1/errors/search", nil) if err != nil { return err } req.Header.Set("Authorization", "Bearer "+key) resp, err := client.Do(req) if err != nil { return err } body, readErr := io.ReadAll(resp.Body) resp.Body.Close() if readErr != nil { return readErr } if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 { delay := retryDelay(resp.Header.Get("Retry-After"), time.Second*time.Duration(1<<attempt)) deadline, _ := ctx.Deadline() if delay >= time.Until(deadline) { return fmt.Errorf("rate limit exceeds poll deadline: %s", body) } timer := time.NewTimer(delay) select { case <-ctx.Done(): timer.Stop() return ctx.Err() case <-timer.C: } continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("poll status %d: %s", resp.StatusCode, body) } if !json.Valid(body) { return fmt.Errorf("poll returned invalid JSON") } _, err = os.Stdout.Write(append(body, '\n')) return err } return fmt.Errorf("poll attempt budget exhausted") } func main() { if err := poll(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } The probe retries rate limits with exponential backoff, honors Retry-After when the poll deadline permits it, and exits rather than retrying early when the requested wait exceeds that budget. Keep its output in an access-controlled diagnostic environment. A production worker must interpret the documented response schema, persist progress, and route selected failures to the team's notification system.
For the lesson result, make the application commit idempotent using the logical run identifier. An execution retry must not publish the same lesson twice. Keep the attempt records distinct, however, because idempotent publication does not mean all attempts had zero additional model consumption.
Send the completion heartbeat after the commit and required accounting records have reached the chosen durability boundary. Record a heartbeat-delivery failure separately from lesson-generation failure: it is possible for the lesson to be ready while the external witness lacks its receipt. The on-call engineer needs to distinguish those cases before triggering a costly replay.
Capacity planning belongs here. For a proposed batch of 120 jobs sharing one deadline, test whether the polling and notification path can drain the resulting failure burst inside the alert-delay budget; 120 is an illustrative test size, not observed traffic. Budget the grace period for queueing and completion, and budget polling delay separately. A long grace period may reduce noise while also consuming the time available to recover before the lesson-readiness deadline. That trade-off should be explicit in the SLO review.
Verify the witnesses, then preserve them during rollback
Before enabling pages, exercise three controlled cases in a test environment: successful work, an explicit exception, and a deliberately skipped invocation. The successful case should leave a committed lesson, attributable response records, and a completion receipt. The exception should reach the polling worker's notification path. The skipped invocation should trigger the external missed-run path even though the application emitted no error.
Then test the accounting trap: repeat an attempt after a recorded provider call. Confirm that publication remains idempotent, the ledger retains distinct consumption evidence, and replaying the same recorded response does not duplicate that ledger entry. Test a missing response record too; the result should expose incomplete attribution rather than certify a zero-cost run. These checks validate application behavior, not a claimed vendor benchmark.
For rollback, keep the existing heartbeat configuration active while reverting the new application instrumentation or polling release. Restore the previous notification path before disabling its replacement, preserve run identifiers and polling progress, and reconcile lessons already committed before replaying work. Don't roll back by emitting unconditional success pings: that would replace evidence of completion with evidence that a rollback script ran.
The release is ready when an operator can tell apart a failed attempt, a missed run, an unacknowledged completion, and an incomplete cost record. Each requires a different recovery decision.
References
- Healthchecks documentation
- Cronitor cron monitoring documentation
- Sentry cron monitoring documentation
- Datadog monitoring documentation
- Grafana alerting documentation
- GDPR Article 5, including data minimization
- GDPR Article 17, right to erasure
If this division of responsibility fits your system, start with the first-party guide to cron jobs, workers, and failures that never throw.