[英]ModuleNotFoundError with one Prefect flow, but not the other
[英]Combine a Parameterized Prefect flow with a Schedule that varies by parameter
我希望能夠重復使用相同的參數化Prefect流程,但其中的Schedule因輸入而異。 例如:
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
有什么建議?
這現在可以在 Prefect 的master 分支上實現,並將在下周隨 0.9.2 發布: Clocks API現在允許為每個時鍾提供參數,這些參數將傳遞給從該時鍾生成的每個流程運行。 在你的情況下,你可以這樣做:
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.