[英]Combine a Parameterized Prefect flow with a Schedule that varies by parameter
I'd like to be be able to re-use the same Parameterized Prefect flow, but where the Schedule varies by inputs.我希望能够重复使用相同的参数化Prefect流程,但其中的Schedule因输入而异。 So for example:
例如:
from prefect import task, Flow, Task, Parameter
from prefect.schedules import CronSchedule
diurnal = ['rooster', 'dog']
nocturnal = ['owl', 'hampster']
# Schedules
diurnal_schedule = CronSchedule("50 7 * * mon,wed")
nocturnal_schedule = CronSchedule("15 12 * * tue,thu")
# Flow is common to both types, though with different schedules.
with Flow(name="wakuptime") as this_flow:
animals = Parameter("animals")
wakeup(animals)
this_flow.run(parameters = dict(animals = diurnal)) on diurnal_schedule
this_flow.run(parameters = dict(animals = nocturnal)) on nocturnal_schedule
Any suggestions?有什么建议?
This is now possible on the master branch of Prefect and will be released with 0.9.2 next week: the Clocks API now allows for providing parameters to each clock that will be passed to each flow run generated from that clock.这现在可以在 Prefect 的master 分支上实现,并将在下周随 0.9.2 发布: Clocks API现在允许为每个时钟提供参数,这些参数将传递给从该时钟生成的每个流程运行。 In your case, you can do:
在你的情况下,你可以这样做:
from prefect import task, Flow, Task, Parameter
from prefect.schedules import clocks, Schedule
diurnal = ['rooster', 'dog']
nocturnal = ['owl', 'hampster']
# Clocks
diurnal_clock = clocks.CronClock("50 7 * * mon,wed", parameter_defaults={"animals": diurnal})
nocturnal_clock = clocks.CronClock("15 12 * * tue,thu", parameter_defaults={"animals": nocturnal})
# the full schedule
schedule = Schedule(clocks=[diurnal_clock, nocturnal_clock])
# Flow is common to both types, though with different schedules.
with Flow(name="wakuptime", schedule=schedule) as this_flow:
animals = Parameter("animals", default=[])
wakeup(animals)
# will run on the schedule with varying parameter values
this_flow.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.