Skip to content

Commit

Permalink
Deprecate cron_expression (#2402)
Browse files Browse the repository at this point in the history
* Deprecate `cron_expression`

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Use pytest

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

---------

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
  • Loading branch information
eapolinario and eapolinario committed May 10, 2024
1 parent e6e08f9 commit c0eca6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
13 changes: 5 additions & 8 deletions flytekit/core/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/flytekit/unit/core/test_launch_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"]
)
Expand Down
22 changes: 12 additions & 10 deletions tests/flytekit/unit/core/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down

0 comments on commit c0eca6a

Please sign in to comment.