Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
1 change: 1 addition & 0 deletions supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ schema_paths = [
"./schemas/users.sql",
"./schemas/events_member.sql",
"./schemas/events_rush.sql",
"./schemas/ping_health.sql",
]

[db.seed]
Expand Down
55 changes: 55 additions & 0 deletions supabase/migrations/20251129202014_healthcheck_table.sql
Original file line number Diff line number Diff line change
@@ -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";


6 changes: 6 additions & 0 deletions supabase/schemas/ping_health.sql
Original file line number Diff line number Diff line change
@@ -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 ()
);
4 changes: 4 additions & 0 deletions supabase/seed.sql
Original file line number Diff line number Diff line change
@@ -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;