Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for Redis timeout error in dequeue method #196

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions saq/queue/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

try:
from redis import asyncio as aioredis
from redis.exceptions import TimeoutError as RedisTimeoutError
except ModuleNotFoundError as e:
raise MissingDependencyError(
"Missing dependencies for Redis. Install them with `pip install saq[redis]`."
Expand Down Expand Up @@ -335,24 +336,28 @@ async def abort(self, job: Job, error: str, ttl: float = 5) -> None:
await self.redis.lrem(self._active, 0, job.id)

async def dequeue(self, timeout: float = 0) -> Job | None:
if await self.version() < (6, 2, 0):
job_id = await self.redis.brpoplpush(
self._queued,
self._active,
timeout, # type:ignore[arg-type]
)
else:
job_id = await self.redis.blmove(
self._queued,
self._active,
timeout,
"LEFT",
"RIGHT",
)
try:
if await self.version() < (6, 2, 0):
job_id = await self.redis.brpoplpush(
self._queued,
self._active,
timeout, # type:ignore[arg-type]
)
else:
job_id = await self.redis.blmove(
self._queued,
self._active,
timeout,
"LEFT",
"RIGHT",
)
except RedisTimeoutError:
logger.debug("Dequeue timed out")
return None

if job_id is not None:
return await self._get_job_by_id(job_id)

logger.debug("Dequeue timed out")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer handle anymore right

return None

async def listen(
Expand Down
Loading