Skip to content

Commit

Permalink
feat(python): add remove method in queue (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Jul 14, 2023
1 parent 3b6f33e commit 808ee72
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/bullmq/job.py
Expand Up @@ -205,7 +205,8 @@ def fromJSON(queue: Queue, rawData: dict, jobId: str | None = None):
async def fromId(queue: Queue, jobId: str):
key = f"{queue.prefix}:{queue.name}:{jobId}"
raw_data = await queue.client.hgetall(key)
return Job.fromJSON(queue, raw_data, jobId)
if len(raw_data):
return Job.fromJSON(queue, raw_data, jobId)


def optsFromJSON(rawOpts: dict) -> dict:
Expand Down
3 changes: 3 additions & 0 deletions python/bullmq/queue.py
Expand Up @@ -216,3 +216,6 @@ def close(self):
Close the queue instance.
"""
return self.redisConnection.close()

def remove(self, job_id: str):
return self.scripts.remove(job_id)
8 changes: 8 additions & 0 deletions python/tests/queue_tests.py
Expand Up @@ -368,6 +368,14 @@ def failing(job: Job, result):
await queue.close()
await worker.close()

async def test_remove_job(self):
queue = Queue(queueName)
job = await queue.add("test", {"foo": "bar"}, {})
await queue.remove(job.id)
job = await Job.fromId(queue, job.id)
self.assertIsNone(job)

await queue.close()

if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_flow.ts
Expand Up @@ -1377,6 +1377,8 @@ describe('flows', () => {
return resolve();
}

await delay(200);

throw new Error('failed');
};
});
Expand Down

0 comments on commit 808ee72

Please sign in to comment.