From 62779273c0cf60fe13823b357fcdb3f90362957d Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Thu, 9 May 2024 13:13:42 -0700 Subject: [PATCH 1/2] Deprecate `cron_expression` Signed-off-by: Eduardo Apolinario --- flytekit/core/schedule.py | 13 +++++------- tests/flytekit/unit/core/test_launch_plan.py | 8 +++---- tests/flytekit/unit/core/test_schedule.py | 22 +++++++++++--------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/flytekit/core/schedule.py b/flytekit/core/schedule.py index 4c94884227..20841c725f 100644 --- a/flytekit/core/schedule.py +++ b/flytekit/core/schedule.py @@ -85,14 +85,11 @@ def my_wf(kickoff_time: datetime): ... kickoff_time_input_arg="kickoff_time") """ - if cron_expression is None and schedule is None: - raise AssertionError("Either `cron_expression` or `schedule` should be specified.") - - if cron_expression is not None and offset is not None: - raise AssertionError("Only `schedule` is supported when specifying `offset`.") - - if cron_expression is not None: - CronSchedule._validate_expression(cron_expression) + if cron_expression: + raise AssertionError( + "cron_expression is deprecated and should not be used. Use `schedule` instead. " + "See the documentation for more information." + ) if schedule is not None: CronSchedule._validate_schedule(schedule) diff --git a/tests/flytekit/unit/core/test_launch_plan.py b/tests/flytekit/unit/core/test_launch_plan.py index 20426a254d..f4cd2c42da 100644 --- a/tests/flytekit/unit/core/test_launch_plan.py +++ b/tests/flytekit/unit/core/test_launch_plan.py @@ -44,7 +44,7 @@ def wf(a: int, c: str) -> (int, str): # fixed_and_default_end # schedule_start - sched = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") + sched = CronSchedule(schedule="*/1 * * * *", kickoff_time_input_arg="abc") email_notif = notification.Email( phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED], recipients_email=["my-team@email.com"] ) @@ -122,7 +122,7 @@ def wf(a: int, c: str) -> (int, str): launch_plan.LaunchPlan.get_or_create(workflow=wf, name="get_or_create_fixed") # Schedule Parameter - obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") + obj = CronSchedule(schedule="*/1 * * * *", kickoff_time_input_arg="abc") schedule_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf, name="get_or_create_schedule", schedule=obj) schedule_lp1 = launch_plan.LaunchPlan.get_or_create(workflow=wf, name="get_or_create_schedule", schedule=obj) @@ -323,8 +323,8 @@ def wf(a: int, c: str) -> str: u = t2(a=x, b=y, c=c) return u - obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") - obj1 = CronSchedule("10 * ? * * *", kickoff_time_input_arg="abc") + obj = CronSchedule(schedule="* * * * * *", kickoff_time_input_arg="abc") + obj1 = CronSchedule(schedule="10 * * * * *", kickoff_time_input_arg="abc") slack_notif = notification.Slack( phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED], recipients_email=["my-team@slack.com"] ) diff --git a/tests/flytekit/unit/core/test_schedule.py b/tests/flytekit/unit/core/test_schedule.py index bd76a24405..8f1a74c125 100644 --- a/tests/flytekit/unit/core/test_schedule.py +++ b/tests/flytekit/unit/core/test_schedule.py @@ -10,24 +10,26 @@ def test_cron(): - obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") - assert obj.kickoff_time_input_arg == "abc" - assert obj.cron_expression == "* * ? * * *" - assert obj == CronSchedule.from_flyte_idl(obj.to_flyte_idl()) + with _pytest.raises(AssertionError): + obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") + assert obj.kickoff_time_input_arg == "abc" + assert obj.cron_expression == "* * ? * * *" + assert obj == CronSchedule.from_flyte_idl(obj.to_flyte_idl()) def test_cron_karg(): - obj = CronSchedule(cron_expression="* * ? * * *", kickoff_time_input_arg="abc") - assert obj.kickoff_time_input_arg == "abc" - assert obj.cron_expression == "* * ? * * *" - assert obj == CronSchedule.from_flyte_idl(obj.to_flyte_idl()) + with _pytest.raises(AssertionError): + obj = CronSchedule(cron_expression="* * ? * * *", kickoff_time_input_arg="abc") + assert obj.kickoff_time_input_arg == "abc" + assert obj.cron_expression == "* * ? * * *" + assert obj == CronSchedule.from_flyte_idl(obj.to_flyte_idl()) def test_cron_validation(): - with _pytest.raises(ValueError): + with _pytest.raises(AssertionError): CronSchedule("* * * * * *", kickoff_time_input_arg="abc") - with _pytest.raises(ValueError): + with _pytest.raises(AssertionError): CronSchedule("* * ? * *", kickoff_time_input_arg="abc") From 74f7616880f67709051bb1cc3afe24544cda7e57 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Thu, 9 May 2024 13:37:10 -0700 Subject: [PATCH 2/2] Use pytest Signed-off-by: Eduardo Apolinario --- tests/flytekit/unit/core/test_schedule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/flytekit/unit/core/test_schedule.py b/tests/flytekit/unit/core/test_schedule.py index 516e0b1b19..c66c93d646 100644 --- a/tests/flytekit/unit/core/test_schedule.py +++ b/tests/flytekit/unit/core/test_schedule.py @@ -10,7 +10,7 @@ def test_cron(): - with _pytest.raises(AssertionError): + with pytest.raises(AssertionError): obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc") assert obj.kickoff_time_input_arg == "abc" assert obj.cron_expression == "* * ? * * *" @@ -18,7 +18,7 @@ def test_cron(): def test_cron_karg(): - with _pytest.raises(AssertionError): + with pytest.raises(AssertionError): obj = CronSchedule(cron_expression="* * ? * * *", kickoff_time_input_arg="abc") assert obj.kickoff_time_input_arg == "abc" assert obj.cron_expression == "* * ? * * *"