Skip to content

Commit

Permalink
fix cron scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
trisongz committed Aug 28, 2023
1 parent c1a9e5f commit f70bc18
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions aiokeydb/v2/types/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(
is_leader_process: typing.Optional[bool] = None,
verbose_startup: typing.Optional[bool] = None,
verbose_concurrency: typing.Optional[bool] = True,
**kwargs
): # sourcery skip: low-code-quality
self.queue = queue
self.settings = settings or default_settings
Expand Down
9 changes: 9 additions & 0 deletions aiokeydb/v2/utils/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def validate_cron_schedule(cron_schedule: str) -> str:
raise ValueError(f"Invalid time unit in cron expression: unit: {unit}, num: {num}")
time_units[unit] = f'*/{num}'

if time_units['hours'] != "*" and time_units['minutes'] == '*':
time_units['minutes'] = 0
if time_units['days'] != "*" and time_units['hours'] == '*':
time_units['hours'] = 0
if time_units['weeks'] != "*" and time_units['days'] == '*':
time_units['days'] = 0
if time_units['months'] != "*" and time_units['weeks'] == '*':
time_units['weeks'] = 0

cron_expression = f"{time_units['minutes']} {time_units['hours']} {time_units['days']} {time_units['months']} {time_units['weeks']}"
if time_units['seconds']:
cron_expression += f" {time_units['seconds']}"
Expand Down
2 changes: 1 addition & 1 deletion aiokeydb/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.1.60'
VERSION = '0.1.61'
1 change: 1 addition & 0 deletions tests/test_cron_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
print(f"Pattern: {pattern}\nCron Expression: {cron_expression}\nValid: {is_valid}\nNext Time: {next_time} ({next_time - now:2f} s)\nNext Date: {next_date}")
except ValueError as e:
print(f"Pattern: {pattern}\nError: {str(e)}\n")
print()

0 comments on commit f70bc18

Please sign in to comment.