How can I schedule a deployment, and pass differen...
# prefect-getting-started
w
How can I schedule a deployment, and pass different parameters? I mean on this case for example:
Copy code
@flow(log_prints=True)
def myflow(param: str):
    print(f'flow executed with param={param}')
I want to schedule 10 runs, and each of them with different values for param1. Schedule 1: param=1 Schedule 2: param=2 ...
n
Hi @William Jamir Excuse me jumping in as I'm kinda new here, so there may be better ways from wiser people. But as there were no replies for two days I figured I'd have a go. There is no way that I can see of directly passing variables that persist across runs of a deployed flow. prefect does however have a "blocks" API which is an interface into various backing stores where you might store secrets or other configuration. In your example, you'd probably want a JSON block (saved to an S3Bucket or whatever persistence you want) and then store the per Schedule params as a map in the JSON.
depending on the infrastructure you have you can of course just write them into a file on disk for a fixed server based solution, or use a database or other persistence store if the deployments are distributed.
j
@William Jamir You could also have a parent_flow which takes in a list of parameters and sequentially/concurrently calls my_flow with each param value, i.e
Copy code
@flow
async def parent_flow(params: List[str]):
    for param in params:
        await my_flow(param=param)


@flow(log_prints=True)
async def my_flow(param: str):
    print(f"flow executed with param={param}")

# Deployment
my_flow_deployment = Deployment.build_from_flow(
    flow=parent_flow,
    parameters={"params": ["1", "2"]},
    name="test-deployment"
)
139 Views