Skip to content

Commit 27b47d1

Browse files
sasirvensamuel-sirven-bib
authored andcommitted
Add conversion from old schedules format to the new one
Improve conversion with regex group
1 parent 0b7da83 commit 27b47d1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/service/app_svc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hashlib
55
import json
66
import os
7+
import re
78
import time
89
from collections import namedtuple
910
from datetime import datetime, timezone
@@ -83,11 +84,17 @@ async def run_scheduler(self):
8384
while True:
8485
interval = 60
8586
for s in await self.get_service('data_svc').locate('schedules'):
86-
now = datetime.now(timezone.utc)
8787
if not croniter.croniter.is_valid(s.schedule):
88-
self.log.warning(f"The schedule {s.id} with the format `{s.schedule}` is incompatible with cron!")
89-
continue
88+
match = re.match(r'^(\d{2}):(\d{2}):\d{2}\.\d{6}$', s.schedule)
89+
if match:
90+
hour, minute = match.groups()
91+
s.schedule = f"{minute} {hour} * * *"
92+
self.log.info(f"Converted time schedule {s.id} to cron format: {s.schedule}")
93+
else:
94+
self.log.warning(f"The schedule {s.id} with the format `{s.schedule}` is incompatible with cron!")
95+
continue
9096

97+
now = datetime.now()
9198
cron = croniter.croniter(s.schedule, now)
9299
diff = now - cron.get_prev(datetime)
93100
if interval > diff.total_seconds() > 0:

0 commit comments

Comments
 (0)