return ret
-RETENTION_MULTIPLIERS = ['n', 'M', 'h', 'd', 'w', 'm', 'y']
+RETENTION_MULTIPLIERS = ['n', 'm', 'h', 'd', 'w', 'M', 'Y']
TableRowT = Dict[str, Union[int, str]]
self.path = path
self.rel_path = rel_path
self.schedule = schedule
+ # test to see if period and spec are valid
+ # this test will throw a ValueError exception if
+ # period is negative or zero
+ # spec is empty or other than n,m,h,d,w,M,Y
+ rep = self.repeat
self.retention = json.loads(retention_policy)
if start is None:
now = datetime.now(timezone.utc)
@property
def repeat(self) -> int:
- period, mult = self.parse_schedule(self.schedule)
- if mult == 'M':
+ period = -1
+ mult = ""
+ try:
+ period, mult = self.parse_schedule(self.schedule)
+ except ValueError:
+ raise ValueError('invalid schedule specified - period should be '
+ 'non-zero positive value and multiplier should '
+ 'be one of h,d,w,M,Y e.g. 1h or 4d etc.')
+ if period <= 0:
+ raise ValueError('invalid schedule specified - period must be a '
+ 'non-zero positive value e.g. 1h or 4d etc.')
+ # 'm' is only for developer testing of minute level snapshots
+ if mult == 'm':
return period * 60
elif mult == 'h':
return period * 60 * 60
return period * 60 * 60 * 24
elif mult == 'w':
return period * 60 * 60 * 24 * 7
+ elif mult == 'M':
+ return period * 60 * 60 * 24 * 30
+ elif mult == 'Y':
+ return period * 60 * 60 * 24 * 365
else:
- raise ValueError(f'schedule multiplier "{mult}" not recognized')
+ raise ValueError('invalid schedule specified - multiplier should '
+ 'be one of h,d,w,M,Y')
UPDATE_LAST = '''UPDATE schedules_meta
SET
# NOTE: prune set has tz suffix stripped out.
("n", SNAPSHOT_TS_FORMAT),
# TODO remove M for release
- ("M", '%Y-%m-%d-%H_%M'),
+ ("m", '%Y-%m-%d-%H_%M'),
("h", '%Y-%m-%d-%H'),
("d", '%Y-%m-%d'),
("w", '%G-%V'),
- ("m", '%Y-%m'),
- ("y", '%Y'),
+ ("M", '%Y-%m'),
+ ("Y", '%Y'),
])
keep = []
if not retention:
return DBConnectionManager(dbinfo)
def _is_allowed_repeat(self, exec_row: Dict[str, str], path: str) -> bool:
- if Schedule.parse_schedule(exec_row['schedule'])[1] == 'M':
+ if Schedule.parse_schedule(exec_row['schedule'])[1] == 'm':
if self.allow_minute_snaps:
log.debug(('Minute repeats allowed, '
f'scheduling snapshot on path {path}'))
Optional[str], Optional[str]]) -> None:
sched = Schedule(*args)
log.debug(f'repeat is {sched.repeat}')
- if sched.parse_schedule(sched.schedule)[1] == 'M' and not self.allow_minute_snaps:
+ if sched.parse_schedule(sched.schedule)[1] == 'm' and not self.allow_minute_snaps:
log.error('not allowed')
- raise ValueError('no minute snaps allowed')
+ raise ValueError('invalid schedule specified - multiplier should '
+ 'be one of h,d,w,M,Y')
log.debug(f'attempting to add schedule {sched}')
with self.get_schedule_db(fs) as conn_mgr:
db = conn_mgr.dbinfo.db