Skip to content

Commit c6ddeaf

Browse files
committed
add worker_functions table and stopped_at column to workers
1 parent b3ec5c2 commit c6ddeaf

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

pkgs/core/schemas/0055_tables_workers.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ create table if not exists pgflow.workers (
66
function_name text not null,
77
started_at timestamptz not null default now(),
88
deprecated_at timestamptz,
9+
stopped_at timestamptz,
910
last_heartbeat_at timestamptz not null default now()
1011
);
1112

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Worker Functions Table
2+
-- Tracks which edge functions should be pinged by ensure_workers() cron
3+
4+
create table if not exists pgflow.worker_functions (
5+
function_name text not null primary key,
6+
enabled boolean not null default true,
7+
heartbeat_timeout_seconds integer not null default 6,
8+
last_invoked_at timestamptz,
9+
created_at timestamptz not null default now(),
10+
updated_at timestamptz not null default now()
11+
);
12+
13+
comment on table pgflow.worker_functions is
14+
'Registry of edge functions that run pgflow workers, used by ensure_workers() cron';
15+
16+
comment on column pgflow.worker_functions.function_name is
17+
'Name of the Supabase Edge Function';
18+
19+
comment on column pgflow.worker_functions.enabled is
20+
'Whether ensure_workers() should ping this function';
21+
22+
comment on column pgflow.worker_functions.heartbeat_timeout_seconds is
23+
'How long before considering a worker dead (no heartbeat)';
24+
25+
comment on column pgflow.worker_functions.last_invoked_at is
26+
'When ensure_workers() last pinged this function (used for debouncing)';

pkgs/core/src/database-types.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,41 @@ export type Database = {
314314
},
315315
]
316316
}
317+
worker_functions: {
318+
Row: {
319+
created_at: string
320+
enabled: boolean
321+
function_name: string
322+
heartbeat_timeout_seconds: number
323+
last_invoked_at: string | null
324+
updated_at: string
325+
}
326+
Insert: {
327+
created_at?: string
328+
enabled?: boolean
329+
function_name: string
330+
heartbeat_timeout_seconds?: number
331+
last_invoked_at?: string | null
332+
updated_at?: string
333+
}
334+
Update: {
335+
created_at?: string
336+
enabled?: boolean
337+
function_name?: string
338+
heartbeat_timeout_seconds?: number
339+
last_invoked_at?: string | null
340+
updated_at?: string
341+
}
342+
Relationships: []
343+
}
317344
workers: {
318345
Row: {
319346
deprecated_at: string | null
320347
function_name: string
321348
last_heartbeat_at: string
322349
queue_name: string
323350
started_at: string
351+
stopped_at: string | null
324352
worker_id: string
325353
}
326354
Insert: {
@@ -329,6 +357,7 @@ export type Database = {
329357
last_heartbeat_at?: string
330358
queue_name: string
331359
started_at?: string
360+
stopped_at?: string | null
332361
worker_id: string
333362
}
334363
Update: {
@@ -337,6 +366,7 @@ export type Database = {
337366
last_heartbeat_at?: string
338367
queue_name?: string
339368
started_at?: string
369+
stopped_at?: string | null
340370
worker_id?: string
341371
}
342372
Relationships: []
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Modify "workers" table
2+
ALTER TABLE "pgflow"."workers" ADD COLUMN "stopped_at" timestamptz NULL;
3+
-- Create "worker_functions" table
4+
CREATE TABLE "pgflow"."worker_functions" (
5+
"function_name" text NOT NULL,
6+
"enabled" boolean NOT NULL DEFAULT true,
7+
"heartbeat_timeout_seconds" integer NOT NULL DEFAULT 6,
8+
"last_invoked_at" timestamptz NULL,
9+
"created_at" timestamptz NOT NULL DEFAULT now(),
10+
"updated_at" timestamptz NOT NULL DEFAULT now(),
11+
PRIMARY KEY ("function_name")
12+
);
13+
-- Set comment to table: "worker_functions"
14+
COMMENT ON TABLE "pgflow"."worker_functions" IS 'Registry of edge functions that run pgflow workers, used by ensure_workers() cron';
15+
-- Set comment to column: "function_name" on table: "worker_functions"
16+
COMMENT ON COLUMN "pgflow"."worker_functions"."function_name" IS 'Name of the Supabase Edge Function';
17+
-- Set comment to column: "enabled" on table: "worker_functions"
18+
COMMENT ON COLUMN "pgflow"."worker_functions"."enabled" IS 'Whether ensure_workers() should ping this function';
19+
-- Set comment to column: "heartbeat_timeout_seconds" on table: "worker_functions"
20+
COMMENT ON COLUMN "pgflow"."worker_functions"."heartbeat_timeout_seconds" IS 'How long before considering a worker dead (no heartbeat)';
21+
-- Set comment to column: "last_invoked_at" on table: "worker_functions"
22+
COMMENT ON COLUMN "pgflow"."worker_functions"."last_invoked_at" IS 'When ensure_workers() last pinged this function (used for debouncing)';

pkgs/core/supabase/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:uE4Gy3n0TTiHs83gNYMJ63aaTl7OFO5tGkFZy6a1xD0=
1+
h1:IMyCv/DI0r48ffoJN/Lx1SsZLaotPIwNGXbIqw9iB7A=
22
20250429164909_pgflow_initial.sql h1:I3n/tQIg5Q5nLg7RDoU3BzqHvFVjmumQxVNbXTPG15s=
33
20250517072017_pgflow_fix_poll_for_tasks_to_use_separate_statement_for_polling.sql h1:wTuXuwMxVniCr3ONCpodpVWJcHktoQZIbqMZ3sUHKMY=
44
20250609105135_pgflow_add_start_tasks_and_started_status.sql h1:ggGanW4Wyt8Kv6TWjnZ00/qVb3sm+/eFVDjGfT8qyPg=
@@ -18,3 +18,4 @@ h1:uE4Gy3n0TTiHs83gNYMJ63aaTl7OFO5tGkFZy6a1xD0=
1818
20251201105311_pgflow_temp_advisory_lock_for_compilation.sql h1:OmRtiaPYjPuq9P87Px2PH06gdKhHZ0Ro6GfjjS0G+Rs=
1919
20251204115929_pgflow_temp_is_local.sql h1:pjOFO6k8FCmbxp6S7U3fPImsqW81WwdLwq/UZK74BG4=
2020
20251204142050_pgflow_temp_ensure_flow_compiled_auto_detect.sql h1:VwqZiOcVaCahb6BZ918ioFLgwQcF/sy1TR9a4lSnVvs=
21+
20251204145037_pgflow_temp_worker_functions_schema.sql h1:5DJJEP0jcg7yapTe7t6FX2ypZIj92lGvJ12AX8g5fz4=

0 commit comments

Comments
 (0)