Catalogue / supabase-external-job-scheduler
supabase-external-job-scheduler
Older skill: source not recordedSignedSets up a recurring external cron clock for a Supabase Edge Function or an HTTP-exposed PostgREST RPC, covering endpoint hardening with a dedicated cron secret, duplicate protection keyed to the scheduling period, user-approved smoke tests, schedule creation over MCP or REST, and run-history verific…--- name: supabase-external-job-scheduler description: > Connects a Supabase Edge Function or HTTP-facing PostgREST RPC to the Crontap scheduling service, covering access-route selection between MCP and raw REST, endpoint hardening with a dedicated cron secret, crash-safe duplicate suppression keyed to a stable run identity, approval-gated verification calls, schedule creation, and checking delivered runs against Supabase function logs. Use when recurring Supabase HTTPS work needs an external clock with retries, run history, or failure alerts. Not for SQL-only jobs inside Postgres, which belong to pg_cron, and not for scheduling endpoints unrelated to Supabase. ---
Put a Supabase HTTPS endpoint on the Crontap clock
Recurring Supabase work reached over HTTPS — a deployed Edge Function or a PostgREST RPC — gets called on a cadence by Crontap, with retries, delivery history, and alerting. First fork: if the task is pure SQL inside Postgres, stop; that belongs to pg_cron. Everything below assumes an HTTPS endpoint.
Step 1 — Choose how you talk to the scheduler
If the session exposes the create_schedule tool, use MCP. If it does not, stop and put exactly two options to the user, then wait for their explicit pick:
- MCP — connect the scheduler's MCP server at
https://mcp.crontap.com/mcp; offered on all Crontap tiers. - Raw REST — the user sets the environment variables
CRONTAP_CLIENT_IDandCRONTAP_API_KEY; raw API access requires the Ultra plan and bills that account.
Never pick a route yourself: the REST option can commit the account to a paid tier.
Step 2 — Verify the endpoint is worth automating (analysis only)
No deploys, config edits, or secret changes in this step — checks only:
| Check | Why it matters | | --- | --- | | Live at its HTTPS URL | A schedule aimed at an undeployed slug yields nothing but failed deliveries | | Guarded | Reads a dedicated header or bearer value and compares it to a server-side env secret before any work; if gateway JWT verification is off for this function, this check is the only lock on the door | | Fast | Answers within seconds; longer work must be written to a durable queue and acknowledged once enqueued — timeouts multiplied by retries are the main duplicate source | | Narrow | Performs exactly one scoped recurring operation; the scheduler will faithfully invoke whatever is deployed |
If hardening is missing, draft the concrete change (code, env-variable name, rotation plan) and apply or deploy it only after the user approves that specific change. Warn that rotating a secret which live schedules already depend on will break them.
One credential rule outranks convenience: the scheduler receives a dedicated cron secret and nothing broader. Never give it the project's service-role key — the all-powerful admin credential.
Step 3 — Design duplicate suppression before anything fires
Crontap delivers at-least-once: one firing may arrive several times, and every delivery of that firing must resolve to the same run key. Two common designs break this silently; design both out.
Never derive the key from the clock at handling time. A firing at 23:58 retried at 00:03 buckets to two periods, and the real-world effect runs twice. Prefer, in order:
| What the scheduler supplies | Run key to use | | --- | --- | | A per-delivery run identifier (header or body variable) stable across retries | That identifier verbatim | | The scheduled time templated into the body | Scheduled time truncated to the window, in the schedule's timezone | | A fixed body only | A period bucket computed in the function — acceptable solely when fire times sit far from period edges (03:40, never midnight) so the retry horizon cannot straddle one; state this residual risk to the user aloud |
Truncate to the window rather than rounding, so the 03:36 and 03:44 deliveries of a daily 03:40 job share one bucket. Example keys: usage-rollup:2025-06-11 (daily), weekly-digest:2025-W24 (weekly), or a scheduler run id such as run_88231 used verbatim.
Never record completion before the work. Writing a finished-marker up front and answering success when the insert conflicts eats whole periods silently: crash between marker and work, and every retry is told success while that period's work is permanently lost. Use recoverable claim state instead:
create table if not exists scheduled_run ( job text not null, run_key text not null, state text not null default 'claimed', -- 'claimed' -> 'done' claimed_at timestamptz not null default now(), done_at timestamptz, primary key (job, run_key) );
Handler logic, race-safe through the primary key rather than read-then-decide:
- Insert a
claimedrow with an insert that skips on conflict and reports how many rows it wrote. A row written: this delivery owns the run. - The owner performs the work, then sets
state = 'done'anddone_at. When every effect is database work (the PostgREST RPC case), wrap claim, work, and completion in one transaction, so a crash rolls the claim back and the retry starts clean. When effects leave the database (email, third-party APIs), no transaction spans them: the row becomes the recovery ledger, and each external effect needs its own idempotency key. - No row written: read the existing row.
done— a duplicate of finished work; return success and touch nothing.claimed— the row alone cannot tell you whether the previous owner is still working or died mid-run, so treat it as neither by default. Compareclaimed_atagainst the job's longest plausible runtime: a fresh claim likely belongs to a delivery still in flight, so return a retryable failure and change nothing; a claim older than any plausible runtime marks a crashed attempt with an unknown outcome — re-drive it only when every effect is idempotent, or let a person reset the claim after inspecting the evidence. Answering success while the row readsclaimedreports work that may never have finished.
Crash drill — run only with approval
Offer to interrupt one named trial invocation after the claim but before the work, to prove the failure path end to end. Before touching anything, present the exact interruption target (which run, in which environment), the moment of interruption, and the consequences: that period's work missing until recovery, a claim row stranded mid-state, and possible half-applied external effects. Proceed only if the user approves that exact interruption. Afterwards, confirm the next delivery reports failure — not success — and that the recovery path (age-out or manual reset) engages. If the user declines, or no safe mechanism exists, skip the drill and record the untested gap. Interrupt nothing besides the approved run; production schedules and unrelated processes stay untouched.
Verification calls — approval gate
Each call below hits the live endpoint, and two perform the real operation on real data. Name the data touched and any customer-visible effect (sent emails, archived rows, created charges), offer staging or dry-run mode if one exists, and wait for an explicit yes:
- No credential attached — expect
401with zero side effects. - Credential attached — the work runs once; the row moves
claimed→done. - Credential attached again moments later — success returned, no second effect; the row stays
done.
Handle the secret by name only: agree on an environment-variable name, have the user place the cron secret there, and reference the name so the shell injects the value; never read, print, or log it. If the user prefers the secret stay out of this shell entirely, hand over the exact request details for them to run from their own machine and take back the status codes. Any deviation — a 200 without the credential, a 401 with it, or a second durable effect on the repeat — halts everything until function logs and the claim table explain it.
Create the schedule — approval gate
A schedule is a live external resource that begins calling the function immediately. Create, edit, or delete one only after the user approves the exact plan: endpoint URL, cadence in plain words and as a cron expression, timezone, HTTP verb, header names, body, label, and how the credential attaches.
MCP — fill every field except the credential itself:
{
"tool": "create_schedule",
"arguments": {
"url": "https://pzqwkjtypa.supabase.co/functions/v1/nightly-usage-rollup",
"text": "every day at 03:40",
"timezone": "Europe/Berlin",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "value supplied through the tool's secure credential prompt"
},
"body": { "job": "usage-rollup" },
"label": "Supabase nightly usage rollup"
}
}Take the real project reference from the user's Supabase project URL and the deployed slug, never the placeholder above.
REST (only on the Ultra route chosen in Step 1) — after approval, POST to https://api.crontap.com/v1/schedule:
curl --fail-with-body -X POST https://api.crontap.com/v1/schedule \ -H "ClientId: $CRONTAP_CLIENT_ID" \ -H "ApiKey: $CRONTAP_API_KEY" \ -H "Content-Type: application/json" \ --data @usage-rollup.json
| Body field | Meaning | Example | | --- | --- | --- | | url | Deployed HTTPS endpoint | the nightly-usage-rollup URL above | | interval | Cadence as a cron expression | 40 3 * * * | | timezone | IANA zone the expression is evaluated in | Europe/Berlin | | verb | Method used for every call | POST | | headers | Sent on every call; carries the credential | Content-Type plus Authorization | | data | Fixed JSON body for every call | {"job": "usage-rollup"} | | label | Name shown in history and alerts | Supabase nightly usage rollup |
Prepare the JSON file with every field except the Authorization value; the user inserts the cron secret themselves before the command runs, or attaches it through the Crontap console. Never read the file back afterwards, and never echo the two variables — their values stay unseen.
If the API rejects the cadence or a capacity limit, its response carries four options. Show the user all four exactly as returned, mark the smallest one that covers the workload, and leave the decision to them — upgrades spend money and are never your call.
Prefer MCP whenever available, because it keeps the credential out of the transcript. If the connected server offers no secure credential input, do not paste the raw secret into the arguments as a workaround: have the user attach it via the Crontap console, or state that this route cannot carry the secret safely and stop.
Confirm the first deliveries
- Read the schedule back; the resolved cadence must match the plain-language intent exactly — a request for Sunday 23:10 firings in America/Chicago must not resolve to a parser's guess.
- Watch the first retained run and its outcome.
- Match scheduler history timestamps against Supabase function logs; each delivery should appear in both.
- Expect one
donerow per elapsed period in the claim table. Missing rows point to 401s or timeouts; doubled real-world effects beside single rows mean work is escaping the claim.
When deliveries misbehave
| Symptom | Likely cause | Action | | --- | --- | --- | | 401 from Supabase | Gateway JWT check or the function's own secret check refused the call | Identify which layer rejected it; confirm the header name and credential match what the function reads | | 404 from Supabase | Wrong project reference, slug, or deploy environment | Re-read both from the live project and its deploy state | | 2xx but no work done | Duplicate was suppressed, or the app failed after responding | Pull function logs and inspect the claim row for that run key | | Timeouts | Too much work packed into one request | Enqueue durably and answer fast; heavier retry settings multiply duplicates |
Preview shortened. The full SKILL.md is in the pack.
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 13.2 kB | 593d562b983a |
| examples.json | 2.6 kB | 39b914dac986 |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 1.0.1 Current | Not recorded | 10 Oct 2026 |
Locking a skill to one version needs Pro.