orangekame3
05/09/2024, 2:26 AMcreate_flow_run_from_deployment
function.
I would like to schedule deployment with custom parameter.
I know, from UI, I can do this with Custom run
, but I couldn't understand how to achieve client function.
https://github.com/PrefectHQ/prefect/blob/cb84f4af54be700d3ba433b90cb36c6da3d36290/src/prefect/client/orchestration.py#L559-L627Marvin
05/09/2024, 2:27 AMparameters
argument of the create_flow_run_from_deployment
function. Here's a link to the documentation that discusses setting parameters in deployments, which could be relevant for your client call as well: Default parameters and overriding parameters.
For example, to set custom parameters from the create_flow_run_from_deployment
, you can include them in the function call. Unfortunately, since Prefect 2.x is new, and I have no experience with it, I can't provide an updated code example directly related to create_flow_run_from_deployment
. However, I do have a general code example that demonstrates task submission, but it doesn't directly answer your question:
python
import time
from prefect import flow, task
@task
def sleep(t: int):
print(f"Going to sleep for {t} seconds...")
time.sleep(t)
print("...and I'm awake!")
@flow(log_prints=True)
def my_flow():
sleep(3) # block the flow for 3 seconds (not concurrently)
future = sleep.submit(2) # submit a task run to the task runner, doesn't block flow
future.wait() # block the flow until the submitted task run is complete
sleep.map([5] * 10) # submit 10 at once, each sleeps for 5 seconds, don't block
if __name__ == "__main__":
my_flow()
Prefect submitting tasks example
The actual function you would use to schedule a deployment with custom parameters likely looks something like this:
python
from prefect import create_flow_run_from_deployment
# Set your deployment ID and custom parameters
deployment_id = "your-deployment-id"
custom_parameters = {"param1": "value1", "param2": "value2"}
# Schedule the deployment with custom parameters
create_flow_run_from_deployment(
deployment_id=deployment_id,
parameters=custom_parameters
)
You will need to replace "your-deployment-id"
with the actual ID of your deployment and define your custom parameters in the custom_parameters
dictionary. Please note that you should adjust the function to match the exact syntax and parameters of Prefect 2.x, as I am extrapolating from my existing knowledge which is not up-to-date on the latest Prefect version.
I recommend checking the latest Prefect 2.x documentation for detailed and accurate examples or use cases related to deployments in Prefect 2.x.orangekame3
05/09/2024, 3:03 AM