CtrlK
BlogDocsLog inGet started
Tessl Logo

g14wxz/edge-function-background-orchestration

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

77

Quality

97%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

Edge Function Background Orchestration

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

Overview

This tile provides two patterns for background processing in Supabase Edge Functions. Light tasks use EdgeRuntime.waitUntil(promise) to fire-and-forget while returning an immediate 200 OK. Massive async workloads are decomposed into pgmq messages, discovered by pg_cron jobs, and processed outside the Edge Function request lifecycle.

Reference

waitUntil Pattern

Deno.serve(async (req) => {
  const payload = await req.json();
  EdgeRuntime.waitUntil(doBackgroundWork(payload));
  return new Response(JSON.stringify({ status: "accepted" }), { status: 200 });
});

pgmq + pg_cron Pattern

-- Create queue
SELECT pgmq.create('my_tasks');

-- Send message
SELECT pgmq.send('my_tasks', '{"action":"process","id":123}'::jsonb);

-- Cron job to consume (every 30 seconds)
SELECT cron.schedule('consume-my-tasks', '30 seconds',
  $$SELECT pgmq.delete('my_tasks', msg_id)
    FROM pgmq.read('my_tasks', 30, 5) WHERE processed = true$$
);

Workload Classification

WorkloadPatternExample
< 30s, single callwaitUntilWebhook relay, email send
Batch, fan-out, pipelinepg_cron + pgmqReport generation, bulk import

Dependencies

  • supabase-mcp-verification -- root prerequisite.
  • pgmq extension -- required for massive async pattern.
  • pg_cron extension -- required for scheduled queue consumption.

Composition Position

  • Stage: execution-runtime
  • Priority: HIGH
  • Executes after database schema and extension tiles are applied.
  • MUST run before any tile that defines webhook handlers or async pipelines.
Workspace
g14wxz
Visibility
Public
Created
Last updated
Publish Source
CLI
Badge
g14wxz/edge-function-background-orchestration badge