Esempio n. 1
0
 def run(self) -> None:
     with session_scope(nullpool=True) as session:
         try:
             self.validate(session=session)
             if not self._model:
                 raise ReportScheduleExecuteUnexpectedError()
             ReportScheduleStateMachine(session, self._model,
                                        self._scheduled_dttm).run()
         except CommandException as ex:
             raise ex
         except Exception as ex:
             raise ReportScheduleUnexpectedError(str(ex))
Esempio n. 2
0
    def run(self) -> None:
        with session_scope(nullpool=True) as session:
            try:
                start_dttm = datetime.utcnow()
                self.validate(session=session)
                if not self._model:
                    raise ReportScheduleExecuteUnexpectedError()
                self.set_state_and_log(session, start_dttm, ReportLogState.WORKING)
                # If it's an alert check if the alert is triggered
                if self._model.type == ReportScheduleType.ALERT:
                    if not AlertCommand(self._model).run():
                        self.set_state_and_log(session, start_dttm, ReportLogState.NOOP)
                        return

                self._send(self._model)

                # Log, state and TS
                self.set_state_and_log(session, start_dttm, ReportLogState.SUCCESS)
            except ReportScheduleAlertGracePeriodError as ex:
                self.set_state_and_log(
                    session, start_dttm, ReportLogState.NOOP, error_message=str(ex)
                )
            except ReportSchedulePreviousWorkingError as ex:
                self.create_log(
                    session,
                    start_dttm,
                    datetime.utcnow(),
                    state=ReportLogState.ERROR,
                    error_message=str(ex),
                )
                session.commit()
                raise
            except CommandException as ex:
                self.set_state_and_log(
                    session, start_dttm, ReportLogState.ERROR, error_message=str(ex)
                )
                # We want to actually commit the state and log inside the scope
                session.commit()
                raise