def test_map_tasks_only(): @workflow def wf1(a: int): print(f"{a}") with pytest.raises(ValueError): @workflow def wf2(a: typing.List[int]): return map_task(wf1)(a=a) lp = LaunchPlan.create("test", wf1) with pytest.raises(ValueError): @workflow def wf3(a: typing.List[int]): return map_task(lp)(a=a)
print(formatted_kickoff_time) # %% # Cron Expression # --------------- # Cron expression strings use the `AWS syntax <http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions>`_. # These are validated at launch plan registration time. from flytekit import CronSchedule, LaunchPlan # creates a launch plan that runs at 10am UTC every day. cron_lp = LaunchPlan.create( "my_cron_scheduled_lp", date_formatter_wf, schedule=CronSchedule( # Note that kickoff_time_input_arg matches the workflow input we defined above: kickoff_time cron_expression="0 10 * * ? *", kickoff_time_input_arg="kickoff_time", ), ) # %% # Fixed Rate # ---------- # If you prefer to use an interval rather than the cron syntax to schedule your workflows, this is currently supported # for Flyte deployments hosted on AWS. # To run ``date_formatter_wf`` every 10 minutes read on below: from datetime import timedelta from flytekit import FixedRate, LaunchPlan
return str(a * 2) @workflow def int_doubler_wf(a: int) -> str: doubled = double_int_and_print(a=a) return doubled # This launch plan triggers email notifications when the workflow execution it triggered reaches the phase `SUCCEEDED`. int_doubler_wf_lp = LaunchPlan.create( "int_doubler_wf", int_doubler_wf, default_inputs={"a": 4}, notifications=[ Email( phases=[WorkflowExecutionPhase.SUCCEEDED], recipients_email=["*****@*****.**"], ) ], ) # %% # Notifications shine when used for scheduled workflows to alert on failures: from datetime import timedelta from flytekit import FixedRate, PagerDuty int_doubler_wf_scheduled_lp = LaunchPlan.create( "int_doubler_wf_scheduled", int_doubler_wf,
from datetime import datetime from flytekit import LaunchPlan, task, workflow from flytekit.models.common import AuthRole @task def print_hello_world() -> str: print("Hello, World") return "Hello" @workflow def hello_world( styx_parameter: datetime, styx_execution_id: str, styx_trigger_id: str, styx_trigger_type: str, styx_workflow_id: str ) -> str: hello = print_hello_world() return hello lp = LaunchPlan.create("morning_greeting", hello_world, auth_role=AuthRole(kubernetes_service_account="e2e-test-sa"))
def square(val: int) -> int: return val * val @workflow def my_wf(val: int) -> int: result = square(val=val) return result default_lp = LaunchPlan.get_default_launch_plan(current_context(), my_wf) square_3 = default_lp(val=3) # %% # The following shows how to specify a user-defined launch plan that defaults the value of 'val' to 4. my_lp = LaunchPlan.create("default_4_lp", my_wf, default_inputs={"val": 4}) square_4 = my_lp() square_5 = my_lp(val=5) # %% # In some cases you may want to **fix** launch plan inputs, such that they can't be overridden at execution call time. my_fixed_lp = LaunchPlan.create("always_2_lp", my_wf, fixed_inputs={"val": 4}) square_2 = my_fixed_lp() # error: # square_1 = my_fixed_lp(val=1) # %% # Putting it all together # ####################### # # Default and fixed inputs can all be used in combination together to simplify individual executions