Skip to content

Commit

Permalink
Update deployment build --rrule input to allow start date and timez…
Browse files Browse the repository at this point in the history
…ones (PrefectHQ#6761)

* Fix rrule input to allow start date and timezone

* make it one-liner

* Fall back to parsing `rrule` as string literal

* Add rrule parsing tests

Co-authored-by: Dustin Ngo <dustin.ngo@gmail.com>
  • Loading branch information
anna-geller and anticorrelator committed Sep 12, 2022
1 parent 567369b commit 8e15297
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/prefect/cli/deployment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Command line interface for working with deployments.
"""
import json
from datetime import timedelta
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -528,7 +529,10 @@ async def build(
elif interval:
schedule = IntervalSchedule(interval=timedelta(seconds=interval))
elif rrule:
schedule = RRuleSchedule(rrule=rrule)
try:
schedule = RRuleSchedule(**json.loads(rrule))
except json.JSONDecodeError:
schedule = RRuleSchedule(rrule=rrule)

# parse storage_block
if storage_block:
Expand Down
46 changes: 46 additions & 0 deletions tests/cli/test_deployment_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,52 @@ def test_auto_apply_flag(self, patch_import, tmp_path):
temp_dir=tmp_path,
)

def test_parsing_rrule_schedule_string_literal(self, patch_import, tmp_path):
invoke_and_assert(
[
"deployment",
"build",
"fake-path.py:fn",
"-n",
"TEST",
"-o",
str(tmp_path / "test.yaml"),
"--rrule",
"DTSTART:20220910T110000\nRRULE:FREQ=HOURLY;BYDAY=MO,TU,WE,TH,FR,SA;BYHOUR=9,10,11,12,13,14,15,16,17",
],
expected_code=0,
temp_dir=tmp_path,
)

deployment = Deployment.load_from_yaml(tmp_path / "test.yaml")
assert (
deployment.schedule.rrule
== "DTSTART:20220910T110000\nRRULE:FREQ=HOURLY;BYDAY=MO,TU,WE,TH,FR,SA;BYHOUR=9,10,11,12,13,14,15,16,17"
)

def test_parsing_rrule_schedule_json(self, patch_import, tmp_path):
invoke_and_assert(
[
"deployment",
"build",
"fake-path.py:fn",
"-n",
"TEST",
"-o",
str(tmp_path / "test.yaml"),
"--rrule",
'{"rrule": "DTSTART:20220910T110000\\nRRULE:FREQ=HOURLY;BYDAY=MO,TU,WE,TH,FR,SA;BYHOUR=9,10,11,12,13,14,15,16,17", "timezone": "America/New_York"}',
],
expected_code=0,
temp_dir=tmp_path,
)

deployment = Deployment.load_from_yaml(tmp_path / "test.yaml")
assert (
deployment.schedule.rrule
== "DTSTART:20220910T110000\nRRULE:FREQ=HOURLY;BYDAY=MO,TU,WE,TH,FR,SA;BYHOUR=9,10,11,12,13,14,15,16,17"
)


class TestOutputMessages:
def test_message_with_work_queue_name(self, patch_import, tmp_path):
Expand Down

0 comments on commit 8e15297

Please sign in to comment.