Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate cron_expression #2402

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=["[email protected]"]
)
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=["[email protected]"]
)
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
Loading