Hi, There are two ways shown to create launch plan...
# ask-the-community
n
Hi, There are two ways shown to create launch plans with LaunchPlan.get_or_create - One is this
Copy code
from flytekit import CronSchedule, LaunchPlan  # noqa: E402

# creates a launch plan that runs every minute.
cron_lp = LaunchPlan.get_or_create(
    name="my_cron_scheduled_lp",
    workflow=date_formatter_wf,
    schedule=CronSchedule(
        # Note that the ``kickoff_time_input_arg`` matches the workflow input we defined above: kickoff_time
        # But in case you are using the AWS scheme of schedules and not using the native scheduler then switch over the schedule parameter with cron_expression
        schedule="*/1 * * * *",  # Following schedule runs every min
        kickoff_time_input_arg="kickoff_time",
    ),
)
, this seems to be in a separate file, which makes sense, I would like to have all my launch plans in one file and import the required workflows from other files. And the second is this
Copy code
from datetime import timedelta  # noqa: E402
from flytekit import FixedRate, LaunchPlan  # noqa: E402

@task
def be_positive(name: str) -> str:
    return f"You're awesome, {name}"

@workflow
def positive_wf(name: str):
    reminder = be_positive(name=name)
    print(f"{reminder}")

fixed_rate_lp = LaunchPlan.get_or_create(
    name="my_fixed_rate_lp",
    workflow=positive_wf,
    # Note that the workflow above doesn't accept any kickoff time arguments.
    # We just omit the ``kickoff_time_input_arg`` from the FixedRate schedule invocation
    schedule=FixedRate(duration=timedelta(minutes=10)),
    fixed_inputs={"name": "you"},
)
where the LaunchPlan.get_or_create call sits below the workflow definition. My question for the second case is - will the launch plan get created when the workflow is registered? I know a default one gets created but I want to know about the one that is defined below the workflow. And for the first case where the launch plans are defined in a separate file, how do I execute the code in this file? Does it need to be inside a task and then I execute this task using pyflyte or is there a way to run the launch plan get_or_create code directly on pyflyte?
I was able to register the launch plan in a separate file as per the 1st example. Two questions - 1. When registering a launch plan this way, does the launch plan get associated with the latest version of the workflow always? and 2. Is there a way to activate the launch plan when creating it or does it need to be done with flytectl once it is created?
I am trying to activate a launch plan with flyte ctl -
flytectl update launchplan my_launch_plan --project sample-ml-project --domain development --version=r_x5ui6DR3iwNlqMGflQ_w== --activate
and I get the success message -
updated launchplan successfully on my_launch_plan
however, when I do
flytectl get launchplan -p sample-ml-project -d development my_launch_plan --latest
I get this -
Copy code
-------------------------- ---------------- ------ ------- -------------------------------------------- -------- --------- 
| VERSION                  | NAME           | TYPE | STATE | SCHEDULE                                   | INPUTS | OUTPUTS |
 -------------------------- ---------------- ------ ------- -------------------------------------------- -------- --------- 
| r_x5ui6DR3iwNlqMGflQ_w== | my_launch_plan |      |       | map[cronSchedule:map[schedule:*/5 * * * *] |        |         |
|                          |                |      |       | kickoffTimeInputArg:start_time]            |        |         |
that is, the type and state are empty. I believe the state should be "active". I can see on the UI that the workflow is associated with the launch plan, but it does not execute. Any idea what might be the issue? @Ketan (kumare3) sorry for the spam 🙂 can you please take a look when you get a chance? Thanks!
k
cc @Kevin Su can you PTAL
k
looking
When registering a launch plan this way, does the launch plan get associated with the latest version of the workflow always
it get associated with the workflow you used in the arg. (
workflow=date_formatter_wf
)
Is there a way to activate the launch plan when creating it or does it need to be done with flytectl once it is created?
it should be activated by default
did you launch the workflow? you created a LP for it, but still need to click the launch button.
n
I did not launch the workflow. Since the launch plan has a schedule to run every 5 mins, wouldn’t it be launched automatically if the launch plan is activated when it is created?
Ok, I launched the workflow once. The LP is scheduled for every 5 mins, and it's past 7 mins now and it didn't launch the workflow.
k
sorry, investigating
one more question, did you run flyte native scheduler or aws scheduler?