Skip to content

Commit

Permalink
fix(python): fixes in obliterate method
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jan 26, 2025
1 parent 64dec2d commit 86e84c3
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions python/bullmq/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,25 @@ def pause(self, pause: bool = True):

async def obliterate(self, count: int, force: bool = False):
"""
Remove a queue completely
Remove a queue completely.
This command calls a Lua script that obliterates the queue
and removes all associated keys, including from bullmq:registry.
"""
keys = self.getKeys(['bullmq:registry', 'meta', ''])
result = await self.commands["obliterate"](keys, args=[count, force or ""])
if (result < 0):
if (result == -1):
raise Exception("Cannot obliterate non-paused queue")
if (result == -2):
raise Exception("Cannot obliterate queue with active jobs")
keys = ['bullmq:registry', *self.getKeys(['meta', ''])]

# Convert force=True to "1", force=False to "", matching the Lua script logic
force_arg = '1' if force else ''

# Pass "args" as expected by your commands["obliterate"] method
result = await self.commands["obliterate"](keys, args=[count, force_arg])

# If the script returns a negative code, raise an exception
if result < 0:
if result == -1:
raise Exception("Cannot obliterate a non-paused queue")
elif result == -2:
raise Exception("Cannot obliterate a queue with active jobs")

return result

def moveJobsToWaitArgs(self, state: str, count: int, timestamp: int) -> int:
Expand Down

0 comments on commit 86e84c3

Please sign in to comment.