-
Notifications
You must be signed in to change notification settings - Fork 15
feat: include options in FlowShape for proper flow creation #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jumski
wants to merge
1
commit into
11-30-feat_edge-worker_add_ensure-compiled_endpoint_to_controlplane
Choose a base branch
from
11-30-include_options_in_flowshape_for_proper_flow_creation
base: 11-30-feat_edge-worker_add_ensure-compiled_endpoint_to_controlplane
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pkgs/core/supabase/migrations/20251130164844_pgflow_temp_options_in_shape.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| -- Modify "create_flow" function | ||
| CREATE OR REPLACE FUNCTION "pgflow"."create_flow" ("flow_slug" text, "max_attempts" integer DEFAULT NULL::integer, "base_delay" integer DEFAULT NULL::integer, "timeout" integer DEFAULT NULL::integer) RETURNS "pgflow"."flows" LANGUAGE sql SET "search_path" = '' AS $$ | ||
| WITH | ||
| defaults AS ( | ||
| SELECT 3 AS def_max_attempts, 5 AS def_base_delay, 60 AS def_timeout | ||
| ), | ||
| flow_upsert AS ( | ||
| INSERT INTO pgflow.flows (flow_slug, opt_max_attempts, opt_base_delay, opt_timeout) | ||
| SELECT | ||
| flow_slug, | ||
| COALESCE(max_attempts, defaults.def_max_attempts), | ||
| COALESCE(base_delay, defaults.def_base_delay), | ||
| COALESCE(timeout, defaults.def_timeout) | ||
| FROM defaults | ||
| ON CONFLICT (flow_slug) DO UPDATE | ||
| SET flow_slug = pgflow.flows.flow_slug -- Dummy update | ||
| RETURNING * | ||
| ), | ||
| ensure_queue AS ( | ||
| SELECT pgmq.create(flow_slug) | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM pgmq.list_queues() WHERE queue_name = flow_slug | ||
| ) | ||
| ) | ||
| SELECT f.* | ||
| FROM flow_upsert f | ||
| LEFT JOIN (SELECT 1 FROM ensure_queue) _dummy ON true; -- Left join ensures flow is returned | ||
| $$; | ||
| -- Modify "_create_flow_from_shape" function | ||
| CREATE OR REPLACE FUNCTION "pgflow"."_create_flow_from_shape" ("p_flow_slug" text, "p_shape" jsonb) RETURNS void LANGUAGE plpgsql SET "search_path" = '' AS $$ | ||
| DECLARE | ||
| v_step jsonb; | ||
| v_deps text[]; | ||
| v_flow_options jsonb; | ||
| v_step_options jsonb; | ||
| BEGIN | ||
| -- Extract flow-level options (may be null) | ||
| v_flow_options := p_shape->'options'; | ||
|
|
||
| -- Create the flow with options (NULL = use default) | ||
| PERFORM pgflow.create_flow( | ||
| p_flow_slug, | ||
| (v_flow_options->>'maxAttempts')::int, | ||
| (v_flow_options->>'baseDelay')::int, | ||
| (v_flow_options->>'timeout')::int | ||
| ); | ||
|
|
||
| -- Iterate over steps in order and add each one | ||
| FOR v_step IN SELECT * FROM jsonb_array_elements(p_shape->'steps') | ||
| LOOP | ||
| -- Convert dependencies jsonb array to text array | ||
| SELECT COALESCE(array_agg(dep), '{}') | ||
| INTO v_deps | ||
| FROM jsonb_array_elements_text(COALESCE(v_step->'dependencies', '[]'::jsonb)) AS dep; | ||
|
|
||
| -- Extract step options (may be null) | ||
| v_step_options := v_step->'options'; | ||
|
|
||
| -- Add the step with options (NULL = use default/inherit) | ||
| PERFORM pgflow.add_step( | ||
| flow_slug => p_flow_slug, | ||
| step_slug => v_step->>'slug', | ||
| deps_slugs => v_deps, | ||
| max_attempts => (v_step_options->>'maxAttempts')::int, | ||
| base_delay => (v_step_options->>'baseDelay')::int, | ||
| timeout => (v_step_options->>'timeout')::int, | ||
| start_delay => (v_step_options->>'startDelay')::int, | ||
| step_type => v_step->>'stepType' | ||
| ); | ||
| END LOOP; | ||
| END; | ||
| $$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
pkgs/core/supabase/tests/create_flow_from_shape/options_compile.test.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| begin; | ||
| select plan(6); | ||
| select pgflow_tests.reset_db(); | ||
|
|
||
| -- Test: Compile a flow with flow-level options from shape | ||
| select pgflow._create_flow_from_shape( | ||
| 'flow_with_options', | ||
| '{ | ||
| "steps": [ | ||
| {"slug": "step1", "stepType": "single", "dependencies": []} | ||
| ], | ||
| "options": { | ||
| "maxAttempts": 5, | ||
| "baseDelay": 10, | ||
| "timeout": 120 | ||
| } | ||
| }'::jsonb | ||
| ); | ||
|
|
||
| -- Verify flow options were applied | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout FROM pgflow.flows WHERE flow_slug = 'flow_with_options' $$, | ||
| $$ VALUES (5, 10, 120) $$, | ||
| 'Flow should have options from shape' | ||
| ); | ||
|
|
||
| -- Test: Compile a flow with step-level options from shape | ||
| select pgflow._create_flow_from_shape( | ||
| 'flow_with_step_options', | ||
| '{ | ||
| "steps": [ | ||
| { | ||
| "slug": "step1", | ||
| "stepType": "single", | ||
| "dependencies": [], | ||
| "options": { | ||
| "maxAttempts": 7, | ||
| "baseDelay": 15, | ||
| "timeout": 90, | ||
| "startDelay": 1000 | ||
| } | ||
| } | ||
| ] | ||
| }'::jsonb | ||
| ); | ||
|
|
||
| -- Verify step options were applied | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout, opt_start_delay FROM pgflow.steps WHERE flow_slug = 'flow_with_step_options' $$, | ||
| $$ VALUES (7, 15, 90, 1000) $$, | ||
| 'Step should have options from shape' | ||
| ); | ||
|
|
||
| -- Test: Compile a flow with no options (defaults should be used) | ||
| select pgflow._create_flow_from_shape( | ||
| 'flow_no_options', | ||
| '{ | ||
| "steps": [ | ||
| {"slug": "step1", "stepType": "single", "dependencies": []} | ||
| ] | ||
| }'::jsonb | ||
| ); | ||
|
|
||
| -- Verify flow uses default options | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout FROM pgflow.flows WHERE flow_slug = 'flow_no_options' $$, | ||
| $$ VALUES (3, 5, 60) $$, | ||
| 'Flow without options in shape should use defaults' | ||
| ); | ||
|
|
||
| -- Verify step uses NULL options (inherits from flow) | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout, opt_start_delay FROM pgflow.steps WHERE flow_slug = 'flow_no_options' $$, | ||
| $$ VALUES (NULL::int, NULL::int, NULL::int, NULL::int) $$, | ||
| 'Step without options in shape should have NULL (inherit from flow)' | ||
| ); | ||
|
|
||
| -- Test: Compile with partial options (missing options should be NULL/default) | ||
| select pgflow._create_flow_from_shape( | ||
| 'flow_partial_options', | ||
| '{ | ||
| "steps": [ | ||
| { | ||
| "slug": "step1", | ||
| "stepType": "single", | ||
| "dependencies": [], | ||
| "options": { | ||
| "timeout": 30 | ||
| } | ||
| } | ||
| ], | ||
| "options": { | ||
| "maxAttempts": 10 | ||
| } | ||
| }'::jsonb | ||
| ); | ||
|
|
||
| -- Verify partial flow options | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout FROM pgflow.flows WHERE flow_slug = 'flow_partial_options' $$, | ||
| $$ VALUES (10, 5, 60) $$, | ||
| 'Flow with partial options should use defaults for missing options' | ||
| ); | ||
|
|
||
| -- Verify partial step options | ||
| select results_eq( | ||
| $$ SELECT opt_max_attempts, opt_base_delay, opt_timeout, opt_start_delay FROM pgflow.steps WHERE flow_slug = 'flow_partial_options' $$, | ||
| $$ VALUES (NULL::int, NULL::int, 30, NULL::int) $$, | ||
| 'Step with partial options should have NULL for missing options' | ||
| ); | ||
|
|
||
| select finish(); | ||
| rollback; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.