table_row['last_pruned'],
table_row['created_count'],
table_row['pruned_count'],
- table_row['active'])
+ table_row['active'],
+ )
def __str__(self):
return f'''{self.path} {self.schedule} {dump_retention(self.retention)}'''
s.retention,
sm.repeat - (strftime("%s", "now") - strftime("%s", sm.start)) %
sm.repeat "until",
- sm.start, sm.repeat
+ sm.start, sm.repeat, sm.schedule
FROM schedules s
INNER JOIN schedules_meta sm ON sm.schedule_id = s.id
WHERE
return json.dumps(dict(self.__dict__),
default=lambda o: o.strftime(SNAP_DB_TS_FORMAT))
+ @classmethod
+ def parse_schedule(cls, schedule):
+ return int(schedule[0:-1]), schedule[-1]
+
@property
def repeat(self):
- mult = self.schedule[-1]
- period = int(self.schedule[0:-1])
+ period, mult = self.parse_schedule(self.schedule)
if mult == 'M':
return period * 60
elif mult == 'h':
self.sqlite_connections = {}
self.active_timers = {}
+ @property
+ def allow_minute_snaps(self):
+ return self.mgr.get_module_option('allow_m_granularity')
+
def get_schedule_db(self, fs):
if fs not in self.sqlite_connections:
self.sqlite_connections[fs] = sqlite3.connect(
ioctx.write_full(SNAP_DB_OBJECT_NAME,
'\n'.join(db_content).encode('utf-8'))
+ def _is_allowed_repeat(self, exec_row, path):
+ if Schedule.parse_schedule(exec_row['schedule'])[1] == 'M':
+ if self.allow_minute_snaps:
+ log.debug(f'Minute repeats allowed, scheduling snapshot on path {path}')
+ return True
+ else:
+ log.info(f'Minute repeats disabled, skipping snapshot on path {path}')
+ return False
+ else:
+ return True
+
+
def refresh_snap_timers(self, fs, path):
try:
log.debug(f'SnapDB on {fs} changed for {path}, updating next Timer')
rows = []
with db:
cur = db.execute(Schedule.EXEC_QUERY, (path,))
- rows = cur.fetchmany(1)
+ all_rows = cur.fetchall()
+ rows = [r for r in all_rows if self._is_allowed_repeat(r, path)][0:1]
timers = self.active_timers.get((fs, path), [])
for timer in timers:
timer.cancel()
# TODO improve interface
def store_snap_schedule(self, fs, path_, args):
sched = Schedule(*args)
+ log.debug(f'repeat is {sched.repeat}')
+ if sched.parse_schedule(sched.schedule)[1] == 'M' and not self.allow_minute_snaps:
+ log.error('not allowed')
+ raise ValueError('no minute snaps allowed')
log.debug(f'attempting to add schedule {sched}')
db = self.get_schedule_db(fs)
sched.store_schedule(db)