From ee31bfd42269840613bedb5d4025daa208121b08 Mon Sep 17 00:00:00 2001 From: William De Rocco <93288641+wderocco8@users.noreply.github.com> Date: Sat, 29 Nov 2025 15:25:02 -0500 Subject: [PATCH] hotfix - testing minutely cron job with ping table --- app.py | 18 ++++-- supabase/config.toml | 1 + .../20251129202014_healthcheck_table.sql | 55 +++++++++++++++++++ supabase/schemas/ping_health.sql | 6 ++ supabase/seed.sql | 4 ++ 5 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 supabase/migrations/20251129202014_healthcheck_table.sql create mode 100644 supabase/schemas/ping_health.sql diff --git a/app.py b/app.py index d7ead15..5b33b77 100644 --- a/app.py +++ b/app.py @@ -154,13 +154,21 @@ def index(): ################################################################ -@app.schedule(Cron("0", "6", "*", "*", "?", "*")) # Daily at 6 AM UTC / 1 AM EST +# @app.schedule(Cron("0", "6", "*", "*", "?", "*")) # Daily at 6 AM UTC / 1 AM EST +@app.schedule(Cron("*", "*", "*", "*", "?", "*")) # minutely for testing def supabase_ping(event): try: + PING_ID = "00000000-0000-0000-0000-000000000001" supabase = SupabaseClient.get_client() - res = supabase.rpc("healthcheck").execute() # harmless keep-alive - print("Supabase healthcheck OK:", res.data) + res = ( + supabase.table("ping_health") + .update({"last_ping": "now()"}) + .eq("id", PING_ID) + .execute() + ) + + print("Supabase ping OK:", res.data) return {"ok": True} except Exception as e: - print("Ping failed:", e) - raise + print("Supabase ping failed:", e) + return {"ok": False, "error": str(e)} diff --git a/supabase/config.toml b/supabase/config.toml index 517cce0..c33c557 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -56,6 +56,7 @@ schema_paths = [ "./schemas/users.sql", "./schemas/events_member.sql", "./schemas/events_rush.sql", + "./schemas/ping_health.sql", ] [db.seed] diff --git a/supabase/migrations/20251129202014_healthcheck_table.sql b/supabase/migrations/20251129202014_healthcheck_table.sql new file mode 100644 index 0000000..8f16678 --- /dev/null +++ b/supabase/migrations/20251129202014_healthcheck_table.sql @@ -0,0 +1,55 @@ +drop function if exists "public"."healthcheck"(); + +create table "public"."ping_health" ( + "id" uuid not null default gen_random_uuid(), + "last_ping" timestamp with time zone not null default now() +); + + +CREATE UNIQUE INDEX ping_health_pkey ON public.ping_health USING btree (id); + +alter table "public"."ping_health" add constraint "ping_health_pkey" PRIMARY KEY using index "ping_health_pkey"; + +grant delete on table "public"."ping_health" to "anon"; + +grant insert on table "public"."ping_health" to "anon"; + +grant references on table "public"."ping_health" to "anon"; + +grant select on table "public"."ping_health" to "anon"; + +grant trigger on table "public"."ping_health" to "anon"; + +grant truncate on table "public"."ping_health" to "anon"; + +grant update on table "public"."ping_health" to "anon"; + +grant delete on table "public"."ping_health" to "authenticated"; + +grant insert on table "public"."ping_health" to "authenticated"; + +grant references on table "public"."ping_health" to "authenticated"; + +grant select on table "public"."ping_health" to "authenticated"; + +grant trigger on table "public"."ping_health" to "authenticated"; + +grant truncate on table "public"."ping_health" to "authenticated"; + +grant update on table "public"."ping_health" to "authenticated"; + +grant delete on table "public"."ping_health" to "service_role"; + +grant insert on table "public"."ping_health" to "service_role"; + +grant references on table "public"."ping_health" to "service_role"; + +grant select on table "public"."ping_health" to "service_role"; + +grant trigger on table "public"."ping_health" to "service_role"; + +grant truncate on table "public"."ping_health" to "service_role"; + +grant update on table "public"."ping_health" to "service_role"; + + diff --git a/supabase/schemas/ping_health.sql b/supabase/schemas/ping_health.sql new file mode 100644 index 0000000..3d555c8 --- /dev/null +++ b/supabase/schemas/ping_health.sql @@ -0,0 +1,6 @@ +-- A tiny table used only for health checks and activity pings +CREATE TABLE + IF NOT EXISTS ping_health ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid (), + last_ping timestamptz NOT NULL DEFAULT now () + ); \ No newline at end of file diff --git a/supabase/seed.sql b/supabase/seed.sql index 2ef0aec..5408d01 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -1,2 +1,6 @@ SET session_replication_role = replica; +-- Healthcheck table seed data +INSERT INTO public.ping_health (id, last_ping) +VALUES ('00000000-0000-0000-0000-000000000001', now()) +ON CONFLICT (id) DO NOTHING; \ No newline at end of file