def test_when_error_handler_raised_exception_it_is_caught(self): job = ScheduledJob(name="job", func=raise_exception, trigger=self.always_fire_trigger, error_handler=raise_exception) job.run_if_needed(ANY_TIMESTAMP) assert_equal(job.state.error, ERROR_MESSAGE)
def test_when_job_raised_exception_error_handler_called(self): mock_error_handler = Mock() job = ScheduledJob(name="job", func=raise_exception, trigger=self.always_fire_trigger, error_handler=mock_error_handler) job.run_if_needed(ANY_TIMESTAMP) assert_true(mock_error_handler.called) assert_equal(job.state.error, ERROR_MESSAGE)
def test_when_job_raised_exception_error_handler_called(): def raise_exception(): raise Exception(ERROR_MESSAGE) mock_trigger = Mock() mock_trigger.should_fire.return_value = True mock_error_handler = Mock() job = ScheduledJob(name="job", func=raise_exception, trigger=mock_trigger, error_handler=mock_error_handler) job.run_if_needed(None) assert_true(mock_error_handler.called) assert_equal(job.last_run.error, ERROR_MESSAGE)
def add_job(self, name, func, trigger): job = ScheduledJob(name, func, trigger, self.error_handler) self.jobs[name] = job self.scheduler.add_job(job)