コード例 #1
0
ファイル: execute.py プロジェクト: dodopizza/superset
 def is_in_grace_period(self) -> bool:
     """
     Checks if an alert is in it's grace period
     """
     last_success = ReportScheduleDAO.find_last_success_log(
         self._report_schedule, session=self._session)
     return (last_success is not None and self._report_schedule.grace_period
             and datetime.utcnow() -
             timedelta(seconds=self._report_schedule.grace_period) <
             last_success.end_dttm)
コード例 #2
0
 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()