Skip to content

Commit 1e3607b

Browse files
authored
Fix using default interval schedule in prefect deploy (#12833)
1 parent 2419977 commit 1e3607b

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/prefect/cli/_prompts.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,19 @@ def prompt_interval_schedule(console):
195195
"""
196196
Prompt the user for an interval in seconds.
197197
"""
198+
default_seconds = 3600
199+
# The interval value must be a timedelta object in order to pass validation as a `PositiveDuration` type in `IntervalSchedule`.
200+
default_duration = timedelta(seconds=default_seconds)
201+
202+
# We show the default in the prompt message rather than enabling `show_default=True` here because `rich` displays timedeltas in hours
203+
# rather than seconds, which would confuse users since we ask them to enter the interval in seconds.
198204
interval = IntervalValuePrompt.ask(
199-
"[bold][green]?[/] Seconds between scheduled runs",
205+
f"[bold][green]?[/] Seconds between scheduled runs ({default_seconds})",
200206
console=console,
201-
default="3600",
207+
default=default_duration,
208+
show_default=False,
202209
)
210+
203211
return IntervalSchedule(interval=interval)
204212

205213

tests/cli/test_deploy.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,41 @@ async def test_deploy_interval_schedule_interactive(
25002500
)
25012501
assert deployment.schedules[0].schedule.interval == timedelta(seconds=42)
25022502

2503+
@pytest.mark.usefixtures("interactive_console", "project_dir")
2504+
async def test_deploy_default_interval_schedule_interactive(
2505+
self, prefect_client, work_pool
2506+
):
2507+
await run_sync_in_worker_thread(
2508+
invoke_and_assert,
2509+
command=(
2510+
f"deploy ./flows/hello.py:my_flow -n test-name --pool {work_pool.name}"
2511+
),
2512+
user_input=(
2513+
# Confirm schedule creation
2514+
readchar.key.ENTER
2515+
# Select interval schedule
2516+
+ readchar.key.ENTER
2517+
# Enter default interval
2518+
+ readchar.key.ENTER
2519+
# accept schedule being active
2520+
+ readchar.key.ENTER
2521+
# decline adding another schedule
2522+
+ readchar.key.ENTER
2523+
# decline save
2524+
+ "n"
2525+
+ readchar.key.ENTER
2526+
),
2527+
expected_code=0,
2528+
expected_output_contains=[
2529+
"Seconds between scheduled runs (3600)",
2530+
],
2531+
)
2532+
2533+
deployment = await prefect_client.read_deployment_by_name(
2534+
"An important name/test-name"
2535+
)
2536+
assert deployment.schedules[0].schedule.interval == timedelta(seconds=3600)
2537+
25032538
@pytest.mark.usefixtures("interactive_console", "project_dir")
25042539
async def test_deploy_cron_schedule_interactive(self, prefect_client, work_pool):
25052540
await run_sync_in_worker_thread(

0 commit comments

Comments
 (0)