CtrlK
BlogDocsLog inGet started
Tessl Logo

g14wxz/edge-function-background-orchestration

Orchestrates long-running Edge Function work via waitUntil, pg_cron, and pgmq patterns.

97

Quality

97%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

edge-function-rules.mdrules/

Edge Function Rules

FATAL Constraints

  • NEVER perform long-running data aggregation purely inside an Edge Function request lifecycle. The response MUST return within the Deno Deploy wall-clock limit.
  • NEVER await a background promise before returning the HTTP response when using the waitUntil pattern. Doing so defeats the purpose and risks timeouts.
  • NEVER set pg_cron polling intervals below 10 seconds. This creates unnecessary database load.
  • NEVER leave consumed pgmq messages undeleted. Every successfully processed message MUST be deleted or archived.
  • NEVER run batch fan-out (> 10 concurrent external calls) inside a single Edge Function invocation. Route through pgmq instead.

Mandatory Behaviors

  • Edge Functions that perform background work MUST use EdgeRuntime.waitUntil(promise) and return 200 OK immediately.
  • Background promises MUST wrap their body in try/catch and log errors via console.error with structured context (function name, request ID).
  • Massive async workloads MUST be decomposed into pgmq messages, discovered by pg_cron, and processed individually.
  • Every pgmq queue MUST have a corresponding dead-letter or archive strategy. Messages that fail processing 3 times MUST be moved to an archive queue.
  • Edge Functions MUST validate incoming payloads before spawning background work. NEVER spawn background work on malformed input.
  • The agent MUST verify that pgmq and pg_cron extensions are enabled before writing any queue or cron SQL. HALT if extensions are missing.

tile.json