Skip to content

Commit

Permalink
Seconds as the first field in cron format (#103) (#104)
Browse files Browse the repository at this point in the history
It's more natural to put `seconds` as the first field, keeping it
consistent with our TS version.
  • Loading branch information
qianl15 authored Sep 12, 2024
1 parent 5be8775 commit ee73d87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dbos/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def scheduler_loop(
func: ScheduledWorkflow, cron: str, stop_event: threading.Event
) -> None:
iter = croniter(cron, datetime.now(timezone.utc))
iter = croniter(cron, datetime.now(timezone.utc), second_at_beginning=True)
while not stop_event.is_set():
nextExecTime = iter.get_next(datetime)
sleepTime = nextExecTime - datetime.now(timezone.utc)
Expand Down
6 changes: 3 additions & 3 deletions tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
def test_scheduled_workflow(dbos: DBOS) -> None:
wf_counter: int = 0

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

time.sleep(2)
assert wf_counter >= 1 and wf_counter <= 3
time.sleep(4)
assert wf_counter > 1 and wf_counter <= 3


def test_scheduled_workflow_exception(dbos: DBOS) -> None:
Expand Down

0 comments on commit ee73d87

Please sign in to comment.