Skip to content

Commit d31e730

Browse files
committed
Rename when_failed to when_exhausted for better naming consistency
1 parent 3858291 commit d31e730

47 files changed

Lines changed: 396 additions & 396 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/conditional-step-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Add conditional step execution with skip infrastructure
1919

2020
**Schema Changes:**
2121

22-
- New columns: required_input_pattern, forbidden_input_pattern, when_unmet, when_failed, skip_reason, skipped_at
22+
- New columns: required_input_pattern, forbidden_input_pattern, when_unmet, when_exhausted, skip_reason, skipped_at
2323
- New step status: 'skipped'
2424
- New function: cascade_skip_steps() for skip propagation
2525
- FlowShape condition fields for auto-compilation drift detection

pkgs/core/schemas/0050_tables_definitions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ create table pgflow.steps (
2727
required_input_pattern jsonb, -- JSON pattern for @> containment check (if)
2828
forbidden_input_pattern jsonb, -- JSON pattern for NOT @> containment check (ifNot)
2929
when_unmet text not null default 'skip', -- What to do when condition not met (skip is natural default)
30-
when_failed text not null default 'fail', -- What to do when handler fails after retries
30+
when_exhausted text not null default 'fail', -- What to do when handler fails after retries
3131
created_at timestamptz not null default now(),
3232
primary key (flow_slug, step_slug),
3333
unique (flow_slug, step_index), -- Ensure step_index is unique within a flow
@@ -38,7 +38,7 @@ create table pgflow.steps (
3838
constraint opt_timeout_is_positive check (opt_timeout is null or opt_timeout > 0),
3939
constraint opt_start_delay_is_nonnegative check (opt_start_delay is null or opt_start_delay >= 0),
4040
constraint when_unmet_is_valid check (when_unmet in ('fail', 'skip', 'skip-cascade')),
41-
constraint when_failed_is_valid check (when_failed in ('fail', 'skip', 'skip-cascade'))
41+
constraint when_exhausted_is_valid check (when_exhausted in ('fail', 'skip', 'skip-cascade'))
4242
);
4343

4444
-- Dependencies table - stores relationships between steps

pkgs/core/schemas/0100_function__cascade_force_skip_steps.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- _cascade_force_skip_steps: Skip a step and cascade to all downstream dependents
2-
-- Used when a condition is unmet (whenUnmet: skip-cascade) or handler fails (whenFailed: skip-cascade)
2+
-- Used when a condition is unmet (whenUnmet: skip-cascade) or handler fails (whenExhausted: skip-cascade)
33
create or replace function pgflow._cascade_force_skip_steps(
44
run_id uuid,
55
step_slug text,

pkgs/core/schemas/0100_function_add_step.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ create or replace function pgflow.add_step(
1010
required_input_pattern jsonb default null,
1111
forbidden_input_pattern jsonb default null,
1212
when_unmet text default 'skip',
13-
when_failed text default 'fail'
13+
when_exhausted text default 'fail'
1414
)
1515
returns pgflow.steps
1616
language plpgsql
@@ -41,7 +41,7 @@ BEGIN
4141
INSERT INTO pgflow.steps (
4242
flow_slug, step_slug, step_type, step_index, deps_count,
4343
opt_max_attempts, opt_base_delay, opt_timeout, opt_start_delay,
44-
required_input_pattern, forbidden_input_pattern, when_unmet, when_failed
44+
required_input_pattern, forbidden_input_pattern, when_unmet, when_exhausted
4545
)
4646
VALUES (
4747
add_step.flow_slug,
@@ -56,7 +56,7 @@ BEGIN
5656
add_step.required_input_pattern,
5757
add_step.forbidden_input_pattern,
5858
add_step.when_unmet,
59-
add_step.when_failed
59+
add_step.when_exhausted
6060
)
6161
ON CONFLICT ON CONSTRAINT steps_pkey
6262
DO UPDATE SET step_slug = EXCLUDED.step_slug

pkgs/core/schemas/0100_function_compare_flow_shapes.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ BEGIN
121121
);
122122
END IF;
123123

124-
-- Compare whenFailed (structural - affects DAG execution semantics)
125-
IF v_local_step->>'whenFailed' != v_db_step->>'whenFailed' THEN
124+
-- Compare whenExhausted (structural - affects DAG execution semantics)
125+
IF v_local_step->>'whenExhausted' != v_db_step->>'whenExhausted' THEN
126126
v_differences := array_append(
127127
v_differences,
128128
format(
129-
$$Step at index %s: whenFailed differs '%s' vs '%s'$$,
129+
$$Step at index %s: whenExhausted differs '%s' vs '%s'$$,
130130
v_idx,
131-
v_local_step->>'whenFailed',
132-
v_db_step->>'whenFailed'
131+
v_local_step->>'whenExhausted',
132+
v_db_step->>'whenExhausted'
133133
)
134134
);
135135
END IF;

pkgs/core/schemas/0100_function_create_flow_from_shape.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ BEGIN
4949
start_delay => (v_step_options->>'startDelay')::int,
5050
step_type => v_step->>'stepType',
5151
when_unmet => v_step->>'whenUnmet',
52-
when_failed => v_step->>'whenFailed',
52+
when_exhausted => v_step->>'whenExhausted',
5353
required_input_pattern => CASE
5454
WHEN (v_step->'requiredInputPattern'->>'defined')::boolean
5555
THEN v_step->'requiredInputPattern'->'value'

pkgs/core/schemas/0100_function_fail_task.sql

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ DECLARE
1313
v_run_failed boolean;
1414
v_step_failed boolean;
1515
v_step_skipped boolean;
16-
v_when_failed text;
16+
v_when_exhausted text;
1717
v_task_exhausted boolean; -- True if task has exhausted retries
1818
begin
1919

@@ -62,11 +62,11 @@ flow_info AS (
6262
FROM pgflow.runs r
6363
WHERE r.run_id = fail_task.run_id
6464
),
65-
config AS (
65+
config AS (
6666
SELECT
6767
COALESCE(s.opt_max_attempts, f.opt_max_attempts) AS opt_max_attempts,
6868
COALESCE(s.opt_base_delay, f.opt_base_delay) AS opt_base_delay,
69-
s.when_failed
69+
s.when_exhausted
7070
FROM pgflow.steps s
7171
JOIN pgflow.flows f ON f.flow_slug = s.flow_slug
7272
JOIN flow_info fi ON fi.flow_slug = s.flow_slug
@@ -94,53 +94,53 @@ fail_or_retry_task as (
9494
AND task.status = 'started'
9595
RETURNING *
9696
),
97-
-- Determine if task exhausted retries and get when_failed mode
98-
task_status AS (
99-
SELECT
100-
(select status from fail_or_retry_task) AS new_task_status,
101-
(select when_failed from config) AS when_failed_mode,
97+
-- Determine if task exhausted retries and get when_exhausted mode
98+
task_status AS (
99+
SELECT
100+
(select status from fail_or_retry_task) AS new_task_status,
101+
(select when_exhausted from config) AS when_exhausted_mode,
102102
-- Task is exhausted when it's failed (no more retries)
103103
((select status from fail_or_retry_task) = 'failed') AS is_exhausted
104104
),
105105
maybe_fail_step AS (
106106
UPDATE pgflow.step_states
107107
SET
108-
-- Status logic:
109-
-- - If task not exhausted (retrying): keep current status
110-
-- - If exhausted AND when_failed='fail': set to 'failed'
111-
-- - If exhausted AND when_failed IN ('skip', 'skip-cascade'): set to 'skipped'
112-
status = CASE
113-
WHEN NOT (select is_exhausted from task_status) THEN pgflow.step_states.status
114-
WHEN (select when_failed_mode from task_status) = 'fail' THEN 'failed'
115-
ELSE 'skipped' -- skip or skip-cascade
116-
END,
108+
-- Status logic:
109+
-- - If task not exhausted (retrying): keep current status
110+
-- - If exhausted AND when_exhausted='fail': set to 'failed'
111+
-- - If exhausted AND when_exhausted IN ('skip', 'skip-cascade'): set to 'skipped'
112+
status = CASE
113+
WHEN NOT (select is_exhausted from task_status) THEN pgflow.step_states.status
114+
WHEN (select when_exhausted_mode from task_status) = 'fail' THEN 'failed'
115+
ELSE 'skipped' -- skip or skip-cascade
116+
END,
117117
failed_at = CASE
118-
WHEN (select is_exhausted from task_status) AND (select when_failed_mode from task_status) = 'fail' THEN now()
119-
ELSE NULL
120-
END,
118+
WHEN (select is_exhausted from task_status) AND (select when_exhausted_mode from task_status) = 'fail' THEN now()
119+
ELSE NULL
120+
END,
121121
error_message = CASE
122122
WHEN (select is_exhausted from task_status) THEN fail_task.error_message
123123
ELSE NULL
124124
END,
125125
skip_reason = CASE
126-
WHEN (select is_exhausted from task_status) AND (select when_failed_mode from task_status) IN ('skip', 'skip-cascade') THEN 'handler_failed'
126+
WHEN (select is_exhausted from task_status) AND (select when_exhausted_mode from task_status) IN ('skip', 'skip-cascade') THEN 'handler_failed'
127127
ELSE pgflow.step_states.skip_reason
128128
END,
129129
skipped_at = CASE
130-
WHEN (select is_exhausted from task_status) AND (select when_failed_mode from task_status) IN ('skip', 'skip-cascade') THEN now()
130+
WHEN (select is_exhausted from task_status) AND (select when_exhausted_mode from task_status) IN ('skip', 'skip-cascade') THEN now()
131131
ELSE pgflow.step_states.skipped_at
132132
END,
133133
-- Clear remaining_tasks when skipping (required by remaining_tasks_state_consistency constraint)
134134
remaining_tasks = CASE
135-
WHEN (select is_exhausted from task_status) AND (select when_failed_mode from task_status) IN ('skip', 'skip-cascade') THEN NULL
135+
WHEN (select is_exhausted from task_status) AND (select when_exhausted_mode from task_status) IN ('skip', 'skip-cascade') THEN NULL
136136
ELSE pgflow.step_states.remaining_tasks
137137
END
138138
FROM fail_or_retry_task
139139
WHERE pgflow.step_states.run_id = fail_task.run_id
140140
AND pgflow.step_states.step_slug = fail_task.step_slug
141141
RETURNING pgflow.step_states.*
142142
)
143-
-- Update run status: only fail when when_failed='fail' and step was failed
143+
-- Update run status: only fail when when_exhausted='fail' and step was failed
144144
UPDATE pgflow.runs
145145
SET status = CASE
146146
WHEN (select status from maybe_fail_step) = 'failed' THEN 'failed'
@@ -158,9 +158,9 @@ SET status = CASE
158158
WHERE pgflow.runs.run_id = fail_task.run_id
159159
RETURNING (status = 'failed') INTO v_run_failed;
160160

161-
-- Capture when_failed mode and check if step was skipped for later processing
162-
SELECT s.when_failed INTO v_when_failed
163-
FROM pgflow.steps s
161+
-- Capture when_exhausted mode and check if step was skipped for later processing
162+
SELECT s.when_exhausted INTO v_when_exhausted
163+
FROM pgflow.steps s
164164
JOIN pgflow.runs r ON r.flow_slug = s.flow_slug
165165
WHERE r.run_id = fail_task.run_id
166166
AND s.step_slug = fail_task.step_slug;
@@ -193,8 +193,8 @@ IF v_step_failed THEN
193193
);
194194
END IF;
195195

196-
-- Handle step skipping (when_failed = 'skip' or 'skip-cascade')
197-
IF v_step_skipped THEN
196+
-- Handle step skipping (when_exhausted = 'skip' or 'skip-cascade')
197+
IF v_step_skipped THEN
198198
-- Send broadcast event for step skipped
199199
PERFORM realtime.send(
200200
jsonb_build_object(
@@ -211,8 +211,8 @@ IF v_step_skipped THEN
211211
false
212212
);
213213

214-
-- For skip-cascade: cascade skip to all downstream dependents
215-
IF v_when_failed = 'skip-cascade' THEN
214+
-- For skip-cascade: cascade skip to all downstream dependents
215+
IF v_when_exhausted = 'skip-cascade' THEN
216216
PERFORM pgflow._cascade_force_skip_steps(fail_task.run_id, fail_task.step_slug, 'handler_failed');
217217
END IF;
218218

pkgs/core/schemas/0100_function_get_flow_shape.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ as $$
2424
'[]'::jsonb
2525
),
2626
'whenUnmet', step.when_unmet,
27-
'whenFailed', step.when_failed,
27+
'whenExhausted', step.when_exhausted,
2828
'requiredInputPattern', CASE
2929
WHEN step.required_input_pattern IS NULL
3030
THEN '{"defined": false}'::jsonb

pkgs/core/src/database-types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export type Database = {
299299
step_index: number
300300
step_slug: string
301301
step_type: string
302-
when_failed: string
302+
when_exhausted: string
303303
when_unmet: string
304304
}
305305
Insert: {
@@ -315,7 +315,7 @@ export type Database = {
315315
step_index?: number
316316
step_slug: string
317317
step_type?: string
318-
when_failed?: string
318+
when_exhausted?: string
319319
when_unmet?: string
320320
}
321321
Update: {
@@ -331,7 +331,7 @@ export type Database = {
331331
step_index?: number
332332
step_slug?: string
333333
step_type?: string
334-
when_failed?: string
334+
when_exhausted?: string
335335
when_unmet?: string
336336
}
337337
Relationships: [
@@ -431,7 +431,7 @@ export type Database = {
431431
step_slug: string
432432
step_type?: string
433433
timeout?: number
434-
when_failed?: string
434+
when_exhausted?: string
435435
when_unmet?: string
436436
}
437437
Returns: {
@@ -447,7 +447,7 @@ export type Database = {
447447
step_index: number
448448
step_slug: string
449449
step_type: string
450-
when_failed: string
450+
when_exhausted: string
451451
when_unmet: string
452452
}
453453
SetofOptions: {

0 commit comments

Comments
 (0)