feat(worker): add --no-create-pool-if-not-found flag to worker start#21004
feat(worker): add --no-create-pool-if-not-found flag to worker start#21004VittoriaLanzo wants to merge 2 commits intoPrefectHQ:mainfrom
Conversation
Exposes the existing BaseWorker.create_pool_if_not_found kwarg via the CLI so users who manage work pools externally (e.g. via Terraform, Pulumi or a custom provisioning script) can prevent the worker from re-creating the pool if it is absent. Closes PrefectHQ#20980
desertaxle
left a comment
There was a problem hiding this comment.
@VittoriaLanzo, you'll need to update some of the existing tests to pass the CI checks. Please make sure to add at least one test that covers this new functionality as well.
|
Thanks for the review @desertaxle! |
…found flag Fix the 5 failing "Runner, Worker, Settings, Input, and CLI Tests" CI checks. The new create_pool_if_not_found kwarg added in the previous commit is now passed to worker_cls(...), but 6 existing mock-based tests asserted the call signature without it, causing strict assert_called_once_with() failures. Changes: - Add create_pool_if_not_found=True to all 6 existing mock_worker.assert_called_once_with() calls - Add test_start_worker_create_pool_if_not_found_default: verifies the flag defaults to True - Add test_start_worker_no_create_pool_if_not_found: verifies --no-create-pool-if-not-found passes False
… flag Add create_pool_if_not_found=True to all six existing mock_worker assert_called_once_with() calls in tests/cli/test_worker.py, and add two new tests covering the default (True) and explicit --no-create-pool-if-not-found (False) behaviors. Addresses CI failures flagged by @desertaxle on PrefectHQ/prefect#21004. https://claude.ai/code/session_01B9vDLAYgy3rDoVEa5rwZhi
…ectHQ#21004 Implements the create_pool_if_not_found boolean CLI flag on the worker start() command using the correct cyclopts negative= parameter syntax (instead of the typer-style slash notation from the PR). Updates all existing tests that assert on worker_cls() constructor kwargs to include create_pool_if_not_found=True (the default), and adds two new tests covering default behavior and the --no-create-pool-if-not-found flag. https://claude.ai/code/session_01ENHt9FzX43ecFSrPTwA6Q9
Summary
Resolves #20980.
The
BaseWorker.__init__already accepts acreate_pool_if_not_foundkwarg that prevents the worker from auto-creating the work pool when it doesn't exist. This is useful when the work pool is managed externally by Terraform, Pulumi, or another provisioning tool — the worker should fail fast (or wait) rather than silently re-creating the pool.However, there was no way to pass this flag from the CLI. This PR exposes it as a
--create-pool-if-not-found / --no-create-pool-if-not-foundflag onprefect worker start.Changes
create_pool_if_not_found: bool = Trueparameter to thestartcommand insrc/prefect/cli/worker.pyworker_cls(..., create_pool_if_not_found=create_pool_if_not_found)Usage