https://flyte.org logo
#ask-the-community
Title
# ask-the-community
f

Frank Shen

07/20/2023, 6:40 PM
Hello, I have a workflow with a date: str parameter. When I create a launch plan from it, can I set the launch plan’s date inputs to be a dynamic value, e.g. to the current date in ‘2023-07-20’ format?
Copy code
launch_plan.LaunchPlan.get_or_create(
    workflow=wf, name="your_lp_name_1", default_inputs={"date": datetime.now().strftime("%Y-%m-%d")}, 
)
n

Niels Bantilan

07/20/2023, 7:42 PM
as far as I know the only way to pass in a dynamic value is through the
CronSchedule(…, kickoff_time_input_arg)
. The code you have there will have a hard-coded default input.
I guess you could refactor the workflow to dynamically create the date (this will cost a task, tho)
Copy code
@task
def create_now(date: Optional[str]) -> str:
    if date is None:
        return datetime.now().strftime(...)
    return date

@workflow
def wf(date: Optional[str] = None):
    now = create_now(date=date)
    ...
f

Frank Shen

07/20/2023, 10:05 PM
@Niels Bantilan, I tried below and it works.
Copy code
@workflow
def wf(
    dt: str = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
)
n

Niels Bantilan

07/20/2023, 10:47 PM
Really? Have you tried running on a flyte cluster? From what I understand the default value will be hard-coded at compile-time
f

Frank Shen

07/20/2023, 10:50 PM
Yes, it works.
n

Niels Bantilan

07/21/2023, 12:49 AM
I guess we can try again tomorrow :) if it’s “2023-07-21” then it works
f

Frank Shen

08/02/2023, 4:49 PM
@Niels Bantilan, Yes you are correct. The workflow got a fixed dt input value that is determined when the workflow is registered.
I will need to implement your strategy. Thanks
2 Views