Zachary Loertscher
08/14/2023, 7:28 PM.with_options()
on a flow deployment, without using a sub-flow to capture the .with_options()
values?
i.e. the following .with_options()
works locally, but not after I deploy it (running the deployment completely ignores the .with_options()
parameters):
@flow
def my_test_flow():
print('hello')
if __name__ == 'main':
my_test_flow.with_options(name='some other name')()
The following uses a subflow to capture the options before running the flow. It works, but do I HAVE to do it this way?
@flow
def my_test_flow():
print('hello')
@flow
def main_flow():
my_test_flow().with_options(name='some other name')()
if __name__ == 'main':
main_flow()
I'd typically use the @flow
decorator instead, but I need to use .with_options
so that I can utilize some parameter over-loads from my --param
arguments for prefect deployment build
directly on the flowNate
08/14/2023, 7:43 PMFlow
and a Deployment
with_options
is a class method on a Flow
, which means it takes the existing instance of a flow and returns a modified version of it (with your setting overrides) - this flow instance knows nothing about any Deployment
that may refer to it (as intended)
if you're running a pre-defined deployment, you'll want to use `run_deployment`(docs) and provide any overrides like parameters
or flow_run_name
as kwargs thereZachary Loertscher
08/14/2023, 7:53 PMrun_deployment
something you would use like this?
@flow
def my_test_flow():
print('hello')
if __name__ == "main":
run_deployment()
where I was previously doing...
@flow
def my_test_flow():
print('hello')
if __name__ == "main":
my_test_flow()
Just trying to understand how it fits in - it seems like it would replace calling a specific flowNate
08/14/2023, 7:58 PMit seems like it would replace calling a specific flowin a sense - yes!
run_deployment
will trigger a flow run from a deployed flow. so whatever you see when you do
prefect deployment ls
can be triggered with run_deployment
. here's a (somewhat involved) example using run_deployment
run_deployment
, if you call it within a flow like
@flow
def parent():
flow_run = run_deployment("foo-flow/foo-deployment", parameters={"bar": 42})
assert flow_run.state.is_completed()
assert flow_run.state.result() == 42 # assume foo-flow literally just returns bar
then you'll see that this run of foo-flow/foo-deployment
is treated as a subflow run of parent
but it doesnt need to be called from within a flow, you can call it from wherever you have prefectZachary Loertscher
08/14/2023, 8:06 PMrun_deployment
from a separate process, right?Nate
08/14/2023, 8:09 PMif I want to run my deployment from prefect clouddo you mean basically clicking "Custom Run" in the UI on a deployment but only programmatically? if so, yes you'd have to call
run_deployment
from somewhereZachary Loertscher
08/14/2023, 8:11 PMNate
08/14/2023, 8:13 PMZachary Loertscher
08/14/2023, 8:19 PMNate
08/14/2023, 8:19 PM