def __init__( self, app_id, mod_id, rotate, backup_count, max_size=None, secret=None, flush_every=1, file_per_host=False ): """Initializes a facility instance and validtes the input.""" self.app_id = app_id self.mod_id = mod_id self.mod_str = pretty_mod_id(mod_id) if not app_id: raise FacilityError("app_id is required in the facility configuration file") if rotate in self.ROTATE_MODE_TRANSLATIONS: rotate = self.ROTATE_MODE_TRANSLATIONS[rotate] if rotate == "size": if not max_size: raise FacilityError( 'Error parsing facility for {0}:{1}: rotation mode is "size", but no max_size is specified'.format( app_id, self.mod_str ) ) else: try: croniter(rotate) except: raise FacilityError( 'Error parsing facility for {0}:{1}: "{2}" is not a valid rotation mode'.format( app_id, self.mod_str, rotate ) ) if not isinstance(backup_count, int) or backup_count <= 0: raise FacilityError( "Error parsing facility for {0}:{1}: backup_count must be a positive integer".format( app_id, self.mod_str ) ) if max_size and (not isinstance(max_size, int) or max_size <= 0): raise FacilityError( "Error parsing facility for {0}:{1}: if specified, max_size must be a positive integer".format( app_id, self.mod_str ) ) if flush_every and (not isinstance(flush_every, int) or flush_every <= 0): raise FacilityError( "Error parsing facility for {0}:{1}: if specified, flush_every must be a positive integer".format( app_id, self.mod_str ) ) self.rotate = rotate self.backup_count = int(backup_count) self.secret = secret self.max_size = max_size self.flush_every = flush_every self.file_per_host = file_per_host
def get_next_execution(self, job_id, schedule, now): '''Calculates the next time the job should run.''' if job_id not in self.db: self.db[job_id] = str(now) last_executed = float(self.db[job_id]) return croniter(schedule, last_executed).get_next()
def __init__(self, app_id, mod_id, rotate, backup_count, max_size=None, secret=None, flush_every=1, file_per_host=False): '''Initializes a facility instance and validtes the input.''' self.app_id = app_id self.mod_id = mod_id self.mod_str = pretty_mod_id(mod_id) if not app_id: raise FacilityError('app_id is required in the facility configuration file') if rotate in self.ROTATE_MODE_TRANSLATIONS: rotate = self.ROTATE_MODE_TRANSLATIONS[rotate] if rotate == 'size': if not max_size: raise FacilityError('Error parsing facility for {0}:{1}: rotation mode is "size", but no max_size is specified'.format(app_id, self.mod_str)) else: try: croniter(rotate) except: raise FacilityError('Error parsing facility for {0}:{1}: "{2}" is not a valid rotation mode'.format(app_id, self.mod_str, rotate)) if not isinstance(backup_count, int) or backup_count <= 0: raise FacilityError('Error parsing facility for {0}:{1}: backup_count must be a positive integer'.format(app_id, self.mod_str)) if max_size and (not isinstance(max_size, int) or max_size <= 0): raise FacilityError('Error parsing facility for {0}:{1}: if specified, max_size must be a positive integer'.format(app_id, self.mod_str)) if flush_every and (not isinstance(flush_every, int) or flush_every <= 0): raise FacilityError('Error parsing facility for {0}:{1}: if specified, flush_every must be a positive integer'.format(app_id, self.mod_str)) self.rotate = rotate self.backup_count = int(backup_count) self.secret = secret self.max_size = max_size self.flush_every = flush_every self.file_per_host = file_per_host