def get_retry_exception(self, attempts: int) -> Optional[exceptions.JobRetry]: schedule_in = self.get_schedule_in(attempts=attempts) if schedule_in is None: return None schedule_at = pendulum.now("UTC").add(seconds=schedule_in) return exceptions.JobRetry(schedule_at)
def get_retry_exception(self, exception: Exception, attempts: int) -> Optional[exceptions.JobRetry]: schedule_in = self.get_schedule_in(exception=exception, attempts=attempts) if schedule_in is None: return None schedule_at = utils.utcnow() + datetime.timedelta(seconds=schedule_in) return exceptions.JobRetry(schedule_at.replace(microsecond=0))
async def test_process_job_retry_failed_job(mocker, test_worker, job_factory, connector): async def coro(*args, **kwargs): pass scheduled_at = pendulum.datetime(2000, 1, 1, tz="UTC") test_worker.run_job = mocker.Mock(side_effect=exceptions.JobRetry( scheduled_at=scheduled_at)) job = job_factory(id=1) await test_worker.job_store.defer_job(job) await test_worker.process_job(job=job, worker_id=0) test_worker.run_job.assert_called_with(job=job, worker_id=0) assert connector.jobs[1]["status"] == "todo" assert connector.jobs[1]["scheduled_at"] == scheduled_at
async def test_process_next_job_retry_failed_job(mocker, app, job_factory): job = job_factory(id=1) await app.job_store.defer_job(job) mocker.patch( "procrastinate.worker.Worker.run_job", side_effect=exceptions.JobRetry( scheduled_at=pendulum.datetime(2000, 1, 1, tz="UTC")), ) test_worker = worker.Worker(app, queues=["queue"]) await test_worker.process_next_job() new_job = app.job_store.jobs[1] assert len(app.job_store.jobs) == 1 assert new_job["status"] == "todo" assert new_job["id"] == 1 assert new_job["scheduled_at"] == pendulum.datetime(2000, 1, 1, tz="UTC")