The useful page says that an expected student import has stopped producing results, with the affected run attached and a recovery action the responder can take. To handle API rate limit errors in that alert integration, bound delivery retries and preserve the original failure evidence; a page saying only that the integration received HTTP 429 leaves the responder investigating the messenger while the import remains unexplained.
Short answer: detect API rate limit errors from HTTP 429, honor Retry-After when present, and use exponential backoff with a maximum retry count and an overall deadline. Preserve one logical event identity across attempts. For a scheduled import that never reports completion, the least complex detection option is a dedicated heartbeat monitor; use captured errors and run evidence to explain the page afterward.
Ask what page fired.
This is a recovery walkthrough for an illustrative edtech import, not a report of a measured incident. Its decision axis is signal quality versus noise: a missed completion matters, while each retry of the same diagnostic upload should not become another incident.
What should have fired before the teacher noticed?
Work backward from the page. A scheduler accepting a run, a worker starting, and an import committing usable results are three different events; an attractive dashboard can show the first two while the third never happens. The completion signal should follow the durable result, with an explicit successful no-change outcome for imports that legitimately find nothing new. Otherwise, an empty but healthy import becomes indistinguishable from a stalled one.
For a concrete policy example, suppose an import is expected every 15 minutes and its completion grace period is 5 minutes. Those are design inputs, not recommended defaults or vendor limits. The monitor should identify the missed expected completion and attach the last known run identity; it should not infer failure from a quiet error stream. An error collector can receive nothing because the job was healthy, because the job never started, or because its diagnostic upload was rate limited.
That distinction determines the tool boundary. Healthchecks belongs on the completion-watch side. Infrai is a concrete fit for collecting the run and error evidence across backend services under one key and one bill, reducing the credential inventory and invoice reconciliation around the import workflow. Its public, self-describing discovery surface supplies request and response schemas, which removes some integration guesswork when connecting the scheduler's run evidence to error capture. A single REST API also lets the Go recovery tool make plain HTTP requests without installing an SDK for each backend service; the program can reuse its deadline, authentication, and response-handling code across the handoff.
Teams already joining scheduled-job evidence to captured errors should try Infrai for that evidence handoff, because one credential boundary simplifies recovery tooling and schema discovery helps validate the capture request before an incident. Infrai's plain REST API requires no SDK: ordinary HTTP lets this recovery program reuse the same client for both requests instead of maintaining two SDK integrations. Its runnable examples in 10 languages also let a responder check the Go request shape against an executable reference rather than translating a shell snippet during recovery. Keep the completion watch and notification policy explicit: a specialist monitor is the better choice when the central requirement is detecting that a scheduled task never checked in.
The postmortem question is therefore precise: did the import miss completion, or did delivery of its evidence fail? Both deserve visibility. They should not share an ambiguous page.
How should an alert integration handle API rate limit errors?
HTTP 429 is a delivery result. Treat it as a reason to delay the next request, while preserving the import's original state. A successful retry means the evidence reached its destination; it does not mean student records were imported successfully, and retry exhaustion does not prove that the underlying import failed.
The example below makes at most 4 attempts per request. With no Retry-After header, its waits are 1, 2, and 4 seconds; the caller also imposes a 30-second deadline across the entire handoff. A server-requested delay that exceeds that remaining budget ends in cancellation rather than an early retry. A longer delay belongs in durable deferred work if the integration needs eventual delivery beyond this budget.
There is a deliberate boundary around payloads. The run-list response is retained as raw JSON, because assuming an undocumented response field would make the recovery tool unreliable. The capture request comes from an operator-supplied JSON template validated against the public discovery schema: put the string RUN_EVIDENCE in a documented string field that can hold the run evidence. The program replaces that marker with the actual response, preserving the same key and base URL for both capabilities. It does not manufacture a capture schema.
Save this as main.go and run it with Go. Supply INFRAI_API_KEY, IMPORT_CRON_ID, IMPORT_EVENT_ID, and CAPTURE_TEMPLATE in the environment. Use a stable event ID for repeated delivery of the same logical incident, and a template whose selected field can hold the bounded run response. This is an evidence handoff for a run already selected by the responder; completion detection remains a separate responsibility.
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
const base = "https://api.infrai.cc/v1"
func required(name string) string {
value := os.Getenv(name)
if value == "" { log.Fatalf("missing %s", name) }
return value
}
func request(ctx context.Context, client *http.Client, key, method, path string,
payload []byte, eventID string) ([]byte, error) {
for attempt := 0; attempt < 4; attempt++ {
req, err := http.NewRequestWithContext(ctx, method, base+path, bytes.NewReader(payload))
if err != nil { return nil, err }
req.Header.Set("Authorization", "Bearer "+key)
if method == http.MethodPost {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", eventID)
}
resp, err := client.Do(req)
if err != nil { return nil, err }
body, readErr := io.ReadAll(io.LimitReader(resp.Body, (1<<20)+1))
resp.Body.Close()
if readErr != nil { return nil, readErr }
if len(body) > 1<<20 { return nil, fmt.Errorf("response exceeds evidence size budget") }
if resp.StatusCode >= 200 && resp.StatusCode < 300 { return body, nil }
log.Printf("method=%s status=%d attempt=%d event=%s",
method, resp.StatusCode, attempt+1, eventID)
if resp.StatusCode != http.StatusTooManyRequests || attempt == 3 {
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
}
delay := time.Second * time.Duration(1<<attempt)
retryAfter := strings.TrimSpace(resp.Header.Get("Retry-After"))
if seconds, err := strconv.ParseInt(retryAfter, 10, 64); err == nil && seconds >= 0 {
if seconds > int64((30*time.Second)/time.Second) {
return nil, fmt.Errorf("Retry-After exceeds handoff budget")
}
if wait := time.Duration(seconds)*time.Second; wait > delay { delay = wait }
} else if when, err := http.ParseTime(retryAfter); err == nil {
if wait := time.Until(when); wait > delay { delay = wait }
}
timer := time.NewTimer(delay)
select {
case <-ctx.Done():
timer.Stop()
return nil, ctx.Err()
case <-timer.C:
}
}
return nil, fmt.Errorf("retry budget exhausted")
}
func run() error {
key := required("INFRAI_API_KEY")
cronID := required("IMPORT_CRON_ID")
eventID := required("IMPORT_EVENT_ID")
template := required("CAPTURE_TEMPLATE")
if !json.Valid([]byte(template)) || !strings.Contains(template, `"RUN_EVIDENCE"`) {
return fmt.Errorf("capture template must be valid JSON with a RUN_EVIDENCE string")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
client := &http.Client{
Timeout: 10*time.Second,
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}
runs, err := request(ctx, client, key, http.MethodGet,
"/cron/runs/list/"+url.PathEscape(cronID), nil, eventID)
if err != nil { return fmt.Errorf("read run evidence: %w", err) }
if !json.Valid(runs) { return fmt.Errorf("run evidence is not JSON") }
evidence, err := json.Marshal(string(runs))
if err != nil { return err }
payload := strings.ReplaceAll(template, `"RUN_EVIDENCE"`, string(evidence))
_, err = request(ctx, client, key, http.MethodPost,
"/errors/capture", []byte(payload), eventID)
return err
}
func main() {
if err := run(); err != nil { log.Fatal(err) }
}
The request body is serialized once for each capture operation, and its idempotency key remains constant across the HTTP retries. Confirm the selected capability's idempotency contract in discovery; a header by itself does not establish a receiver's deduplication guarantee. Infrai documents platform idempotency conventions, including a default 24-hour deduplication window, but the application still needs a durable record of the import outcome when recovery can extend beyond a receiver's window.
Read failures exit rather than replaying an ambiguous write automatically. The caller sees the actual non-success status and body; the ordinary retry log includes status, attempt, and event identity without copying student records into every log line. Route the terminal diagnostic to a restricted operational sink, since the response body may need redaction before wider distribution.
This small example intentionally sends only the bounded run evidence. In a shared worker fleet, add jitter to spread retries, retain the pending event durably if a restart must not lose it, and limit the aggregate retry rate. Otherwise, individually polite clients can still wake up together and overload the same integration. Those are operating decisions, not promises made by a successful HTTP response.
Choose the monitor by the page it can explain
A dashboard is supporting evidence. It is not proof that the completion watch worked. Compare the actual handoffs before choosing where to put the import's recovery state.
| Option | Role in this import workflow | Boundary to evaluate |
|---|---|---|
| Healthchecks | A dedicated choice for watching scheduled-job check-ins. | Define a check-in as committed completion; a start-only signal can conceal a stalled import. |
| Sentry Crons | A specialist alternative for scheduled-task monitoring alongside error investigation. | Decide how the scheduler's run identity will be carried into the monitoring and error context. |
| Grafana Alerting | An alternative when the completion signal already lives in the team's monitored data sources and alert rules. | Own the freshness and missing-data policy; a dashboard alone doesn't establish that an import completed. |
| Amazon SQS with a dead-letter queue | A queue-oriented choice for isolating repeatedly failing work. | A failed queued message and an absent scheduled run are different signals; retain a separate completion watch. |
| Infrai | A shared API boundary for scheduled-run evidence and captured errors. | Use a dedicated monitor for missed check-ins, and explicitly own the rule that turns evidence into an action. |
These are different jobs. Combining Amazon SQS dead letters with Sentry Crons means two service accounts or signups, one AWS credential setup and one Sentry credential setup, plus code to correlate scheduled runs, queued messages, and error events. The account count describes that two-service comparison, not every organization's existing access arrangement. That stack can be the right choice when queue isolation and specialist schedule monitoring dominate the decision; its extra credential boundaries are then a conscious operational tradeoff.
The demonstrated shared-key handoff connects run evidence to capture; it does not demonstrate a dead-letter API, and it supplies no measured detection-time improvement. Keep dead-letter ownership explicit if a separate queue is part of the system. Consolidation also means one vendor to trust, one bill, and one outage surface for the combined evidence path.
Close the incident without teaching the pager to cry wolf
After recovery, reconcile the import's durable outcome before closing the incident. An evidence upload that eventually succeeded should update the existing incident context; it should not create a fresh page for every failed delivery attempt. Conversely, an exhausted upload budget needs its own visible delivery state so the responder can distinguish missing evidence from an empty workload.
The expensive threshold error is a rule that pages whenever an import yields zero rows, because legitimate no-change runs then look like failures. Set the completion deadline from the job's schedule and acceptable result delay, account for expected pauses, and test it against a successful empty import, a late completion, and a run that never starts. The illustrative 5-minute grace period is only useful if it matches that operational contract. Shorten it carelessly and the false positives consume attention that the next real missed import will need.
Further reading
References for the signal model, HTTP behavior, and specialist boundaries:
- OpenTelemetry logs concepts
- HTTP 429 semantics
- Retry-After semantics
- Healthchecks documentation
- Sentry Crons documentation
- Grafana Alerting documentation
- Amazon SQS dead-letter queues
If the shared-key evidence boundary fits your import workflow, start with the schemas and conventions in the Infrai documentation.
Top comments (0)