Skip to content

Commit

Permalink
Add conversion from old schedules format to the new one
Browse files Browse the repository at this point in the history
Improve conversion with regex group
  • Loading branch information
sasirven authored and samuel-sirven-bib committed Sep 24, 2024
1 parent 060dc5a commit d690351
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/service/app_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hashlib
import json
import os
import re
import time
from collections import namedtuple
from datetime import datetime, timezone
Expand Down Expand Up @@ -84,6 +85,12 @@ async def run_scheduler(self):
interval = 60
for s in await self.get_service('data_svc').locate('schedules'):
now = datetime.now(timezone.utc)
match = re.match(r'^(\d{2}):(\d{2}):\d{2}\.\d{6}$', s.schedule)
if match:
hour, minute = match.groups()
s.schedule = f"{minute} {hour} * * *"
self.log.info(f"Converted time schedule {s.id} to cron format: {s.schedule}")

if not croniter.croniter.is_valid(s.schedule):
self.log.warning(f"The schedule {s.id} with the format `{s.schedule}` is incompatible with cron!")
continue
Expand Down

0 comments on commit d690351

Please sign in to comment.