acoustic-carpenter-78188
01/18/2023, 12:34 PM@workflow
def greeting_wf(kickoff_time: datetime, chain: str, country: str):
date = kickoff_time_converter(kickoff_time=kickoff_time)
output_check = generate_output_flag_check_greeting(
date=kickoff_time, chain=chain, country=country
)
output_path = output_path_greeting(date=kickoff_time, chain=chain, country=country)
conditional_flow = (
conditional("flag_check")
.if_(output_check.is_false())
.then(
greeting_shell_task(
date=kickoff_time, chain=chain, country=country, output_path=output_path
)
)
.elif_(output_check.is_true())
.then(
previous_completion(
chain=chain, country=country, date=date, task_name="helloflyte_greeting"
)
)
.else_()
.fail("Something went wrong. Please contact DPAR.")
)
output_check >> conditional_flow
def generate_backfill_workflow(
start_date: datetime, end_date: datetime, base_lp: LaunchPlan, **kwargs
) -> Workflow:
if base_lp.schedule is None:
raise ValueError("Backfill can only be created for scheduled launchplans")
if isinstance(base_lp.schedule, CronSchedule):
pass
else:
raise NotImplementedError("The launchplan schedule needs to be a cron schedule")
if start_date >= end_date:
raise ValueError("Start date should be greater than end date")
sub_name = "_".join(kwargs.values())
wf = Workflow(name=f"backfill-{base_lp.name}-{sub_name}")
lp_iter = croniter(
base_lp.schedule.cron_schedule.schedule,
start_time=start_date,
ret_type=datetime,
)
while True:
next_start_date = lp_iter.get_next()
if next_start_date > end_date:
break
wf.add_launch_plan(
base_lp, kickoff_time=next_start_date, **kwargs
).with_overrides(
node_name=f"{base_lp.name}_{sub_name}_{next_start_date.strftime('%Y-%m-%d')}"
)
return wf
def backfill_greeting(
chain_list: List[str],
country_list: List[str],
start_date: datetime,
num_days: int,
**kwargs,
) -> Workflow:
wf_wrapper = Workflow(name="helloflyte_greeting")
end_date = start_date + timedelta(days=num_days)
for chain in chain_list:
for country in country_list:
wf_wrapper.add_entity(
generate_backfill_workflow(
start_date=start_date,
end_date=end_date,
base_lp=lp_greeting,
chain=chain,
country=country,
**kwargs,
)
).with_overrides(name=f"greeting_{chain}_{country}")
return wf_wrapper
Screenshots
No response
Are you sure this issue hasn't been raised already?
☑︎ Yes
Have you read the Code of Conduct?
☑︎ Yes
flyteorg/flyte