From afe1f6e32d6cdd5f0061902802aefc93eccb290a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 24 Aug 2023 11:11:22 -0400 Subject: [PATCH] [103] add hourly and weekly ranges --- VERSION | 2 +- docs/metadata/details/schedule.md | 22 ++++++------- modules/util.py | 53 +++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/VERSION b/VERSION index f1e49f37..dacf95c4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.19.0-develop102 +1.19.0-develop103 diff --git a/docs/metadata/details/schedule.md b/docs/metadata/details/schedule.md index 01c6bb47..8eee359c 100644 --- a/docs/metadata/details/schedule.md +++ b/docs/metadata/details/schedule.md @@ -10,17 +10,17 @@ These schedules do not trigger PMM to run; they control what PMM will do if it h The scheduling options are: -| Name | Description | Format | Example | -|:-------------|:-------------------------------------------------------------------------------------------------|:----------------------|:----------------------------------| -| Hourly | Update only when the script is run in that hour | hourly(Hour of Day) | `hourly(17)` | -| Daily | Update once a day | daily | `daily` | -| Weekly | Update once a week on the specified day | weekly(Day of Week) | `weekly(sunday)` | -| Monthly | Update once a month on the specified day | monthly(Day of Month) | `monthly(1)` | -| Yearly | Update once a year on the specified day | yearly(MM/DD) | `yearly(01/30)` | -| Range | Updates whenever the date is within the range | range(MM/DD-MM/DD) | `range(12/01-12/31)` | -| Never | Never updates | never | `never` | -| Non Existing | Updates if it doesn't exist | non_existing | `non_existing` | -| All | Requires that all comma separated scheduling options inside its brackets be meet in order to run | all[Options] | `all[weekly(sunday), hourly(17)]` | +| Name | Description | Format | Example | +|:-------------|:-----------------------------------------------------------------------------------------------------------|:---------------------------------------------------|:-------------------------------------------------------------| +| Hourly | Update only when the script is run in that hour or hour range | hourly(Hour of Day)
hourly(Start Hour-End Hour) | `hourly(17)`
`hourly(17-04)` | +| Daily | Update once a day | daily | `daily` | +| Weekly | Update once a week on the specified days (For multiple days use a bar-separated (|) list | weekly(Days of Week) | `weekly(sunday)`
weekly(sunday|tuesday) | +| Monthly | Update once a month on the specified day | monthly(Day of Month) | `monthly(1)` | +| Yearly | Update once a year on the specified day | yearly(MM/DD) | `yearly(01/30)` | +| Range | Updates whenever the date is within the range | range(MM/DD-MM/DD) | `range(12/01-12/31)` | +| Never | Never updates | never | `never` | +| Non Existing | Updates if it doesn't exist | non_existing | `non_existing` | +| All | Requires that all comma separated scheduling options inside its brackets be meet in order to run | all[Options] | `all[weekly(sunday), hourly(17)]` | * `daily` is the default when `schedule` is not specified. * You can run the script multiple times per day but using the `--time` command line argument detailed on the [Run Commands & Environmental Variables Page](../../home/environmental.md#time-to-run). diff --git a/modules/util.py b/modules/util.py index 0464e219..80754039 100644 --- a/modules/util.py +++ b/modules/util.py @@ -603,22 +603,47 @@ def schedule_check(attribute, data, current_time, run_hour, is_all=False): continue param = match.group(1) if run_time.startswith("hour"): - try: - if 0 <= int(param) <= 23: - schedule_str += f"\nScheduled to run on the {num2words(param, to='ordinal_num')} hour" - if run_hour == int(param): - all_check += 1 - else: - raise ValueError - except ValueError: - logger.error(f"Schedule Error: hourly {display} must be an integer between 0 and 23") + if "-" in run_time: + start, end = run_time.split("-") + try: + start = int(start) + end = int(end) + if start != end and 0 <= start <= 23 and 0 <= end <= 23: + schedule_str += f"\nScheduled to run between the {num2words(start, to='ordinal_num')} hour and the {num2words(end, to='ordinal_num')} hour" + if end > start and start <= run_hour <= end: + all_check += 1 + elif start > end and (start <= run_hour or run_hour <= end): + all_check += 1 + else: + raise ValueError + except ValueError: + logger.error(f"Schedule Error: hourly {start}-{end} each must be a different integer between 0 and 23") + else: + try: + if 0 <= int(param) <= 23: + schedule_str += f"\nScheduled to run on the {num2words(param, to='ordinal_num')} hour" + if run_hour == int(param): + all_check += 1 + else: + raise ValueError + except ValueError: + logger.error(f"Schedule Error: hourly {display} must be an integer between 0 and 23") elif run_time.startswith("week"): - if param.lower() not in days_alias: - logger.error(f"Schedule Error: weekly {display} must be a day of the week i.e. weekly(Monday)") + ok_days = param.lower().split("|") + err = None + for ok_day in ok_days: + if ok_day not in days_alias: + err = f"Schedule Error: weekly {display} must be a day of the week i.e. weekly(Monday)" + if err: + logger.error(err) continue - weekday = days_alias[param.lower()] - schedule_str += f"\nScheduled weekly on {pretty_days[weekday]}" - if weekday == current_time.weekday(): + pass_day = False + for ok_day in ok_days: + weekday = days_alias[ok_day] + schedule_str += f"\nScheduled weekly on {pretty_days[weekday]}" + if weekday == current_time.weekday(): + pass_day = True + if pass_day: all_check += 1 elif run_time.startswith("month"): try: