Skip to content

Commit ee73d87

Browse files
authored
Seconds as the first field in cron format (#103) (#104)
It's more natural to put `seconds` as the first field, keeping it consistent with our TS version.
1 parent 5be8775 commit ee73d87

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

dbos/scheduler/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def scheduler_loop(
1717
func: ScheduledWorkflow, cron: str, stop_event: threading.Event
1818
) -> None:
19-
iter = croniter(cron, datetime.now(timezone.utc))
19+
iter = croniter(cron, datetime.now(timezone.utc), second_at_beginning=True)
2020
while not stop_event.is_set():
2121
nextExecTime = iter.get_next(datetime)
2222
sleepTime = nextExecTime - datetime.now(timezone.utc)

tests/scheduler/test_scheduler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
def test_scheduled_workflow(dbos: DBOS) -> None:
1010
wf_counter: int = 0
1111

12-
@DBOS.scheduled("* * * * * *")
12+
@DBOS.scheduled("*/2 * * * * *")
1313
@DBOS.workflow()
1414
def test_workflow(scheduled: datetime, actual: datetime) -> None:
1515
nonlocal wf_counter
1616
wf_counter += 1
1717

18-
time.sleep(2)
19-
assert wf_counter >= 1 and wf_counter <= 3
18+
time.sleep(4)
19+
assert wf_counter > 1 and wf_counter <= 3
2020

2121

2222
def test_scheduled_workflow_exception(dbos: DBOS) -> None:

0 commit comments

Comments
 (0)