[52] add `all` option to schedule

pull/858/head
meisnate12 3 years ago
parent 16be7a9d70
commit 2b6e6f1cec

@ -1 +1 @@
1.16.5-develop51
1.16.5-develop52

@ -67,7 +67,7 @@ collections:
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)` |
@ -75,6 +75,7 @@ The scheduling options are:
| 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` |
| All | Requires that all scheduling option be meet in order to run<br>ex. `all, weekly(sunday), hourly(17)` | all | `all` |
* `daily` is the default when `schedule` isn't 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).

@ -422,17 +422,22 @@ def check_day(_m, _d):
return _m, _d
def schedule_check(attribute, data, current_time, run_hour):
skip_collection = True
range_collection = False
schedule_list = get_list(data)
all_check = 0
schedules_run = 0
is_all = False
next_month = current_time.replace(day=28) + timedelta(days=4)
last_day = next_month - timedelta(days=next_month.day)
schedule_str = ""
for schedule in schedule_list:
for schedule in get_list(data):
run_time = str(schedule).lower()
display = f"{attribute} attribute {schedule} invalid"
if run_time.startswith(("day", "daily")):
skip_collection = False
schedules_run += 1
if run_time == "all":
is_all = True
all_check += 1
elif run_time.startswith(("day", "daily")):
all_check += 1
elif run_time == "never":
schedule_str += f"\nNever scheduled to run"
elif run_time.startswith(("hour", "week", "month", "year", "range")):
@ -446,7 +451,7 @@ def schedule_check(attribute, data, current_time, run_hour):
if 0 <= int(param) <= 23:
schedule_str += f"\nScheduled to run only on the {make_ordinal(int(param))} hour"
if run_hour == int(param):
skip_collection = False
all_check += 1
else:
raise ValueError
except ValueError:
@ -458,14 +463,14 @@ def schedule_check(attribute, data, current_time, run_hour):
weekday = days_alias[param.lower()]
schedule_str += f"\nScheduled weekly on {pretty_days[weekday]}"
if weekday == current_time.weekday():
skip_collection = False
all_check += 1
elif run_time.startswith("month"):
try:
if 1 <= int(param) <= 31:
schedule_str += f"\nScheduled monthly on the {make_ordinal(int(param))}"
if current_time.day == int(param) or (
current_time.day == last_day.day and int(param) > last_day.day):
skip_collection = False
all_check += 1
else:
raise ValueError
except ValueError:
@ -479,7 +484,7 @@ def schedule_check(attribute, data, current_time, run_hour):
schedule_str += f"\nScheduled yearly on {pretty_months[month]} {make_ordinal(day)}"
if current_time.month == month and (current_time.day == day or (
current_time.day == last_day.day and day > last_day.day)):
skip_collection = False
all_check += 1
else:
raise ValueError
except ValueError:
@ -498,14 +503,13 @@ def schedule_check(attribute, data, current_time, run_hour):
range_collection = True
schedule_str += f"\nScheduled between {pretty_months[month_start]} {make_ordinal(day_start)} and {pretty_months[month_end]} {make_ordinal(day_end)}"
if start <= check <= end if start < end else (check <= end or check >= start):
skip_collection = False
all_check += 1
else:
logger.error(f"Schedule Error: {display}")
if len(schedule_str) == 0:
skip_collection = False
if skip_collection and range_collection:
if all_check == 0 or (is_all and schedules_run != all_check):
if range_collection:
raise NotScheduledRange(schedule_str)
elif skip_collection:
else:
raise NotScheduled(schedule_str)
def check_int(value, datatype="int", minimum=1, maximum=None):

Loading…
Cancel
Save