예제 #1
0
 def _raise_already_enqueued(self, exc: exceptions.UniqueViolation,
                             job: jobs.Job):
     if exc.constraint_name == connector.QUEUEING_LOCK_CONSTRAINT:
         raise exceptions.AlreadyEnqueued(
             "Job cannot be enqueued: there is already a job in the queue "
             f"with the lock {job.queueing_lock}") from exc
     raise exc
예제 #2
0
 def _raise_already_enqueued(self, exc: exceptions.UniqueViolation,
                             queueing_lock: Optional[str]):
     if exc.constraint_name == QUEUEING_LOCK_CONSTRAINT:
         raise exceptions.AlreadyEnqueued(
             "Job cannot be enqueued: there is already a job in the queue "
             f"with the queueing lock {queueing_lock}") from exc
     raise exc
예제 #3
0
    async def defer_job(self, job: jobs.Job) -> int:
        try:
            result = await self.connector.execute_query_one(
                query=sql.queries["defer_job"],
                task_name=job.task_name,
                lock=job.lock,
                queueing_lock=job.queueing_lock,
                args=job.task_kwargs,
                scheduled_at=job.scheduled_at,
                queue=job.queue,
            )
        except exceptions.UniqueViolation as exc:
            if exc.constraint_name == connector.QUEUEING_LOCK_CONSTRAINT:
                raise exceptions.AlreadyEnqueued(
                    "Job cannot be enqueued: there is already a job in the queue "
                    f"with the lock {job.queueing_lock}") from exc
            raise

        return result["id"]