def next(self) -> None: if self.is_on_working_timeout(): exception_timeout = ReportScheduleWorkingTimeoutError() self.set_state_and_log( ReportState.ERROR, error_message=str(exception_timeout), ) raise exception_timeout exception_working = ReportSchedulePreviousWorkingError() self.set_state_and_log( ReportState.WORKING, error_message=str(exception_working), ) raise exception_working
def validate( # pylint: disable=arguments-differ self, session: Session = None ) -> None: # Validate/populate model exists self._model = ReportScheduleDAO.find_by_id(self._model_id, session=session) if not self._model: raise ReportScheduleNotFoundError() # Avoid overlap processing if self._model.last_state == ReportLogState.WORKING: raise ReportSchedulePreviousWorkingError() # Check grace period if self._model.type == ReportScheduleType.ALERT: last_success = ReportScheduleDAO.find_last_success_log(session) if ( last_success and self._model.last_state in (ReportLogState.SUCCESS, ReportLogState.NOOP) and self._model.grace_period and datetime.utcnow() - timedelta(seconds=self._model.grace_period) < last_success.end_dttm ): raise ReportScheduleAlertGracePeriodError()