bullmq: [Bug]: Examples in python bullmq documentation are not working
Version
v0.5.6
Platform
Python
What happened?
I tried to run the examples on the below link
The example was not working. As an introduction, there should be ready to use examples
Prerequisite
pip install redis --upgrade
pip install bullmq==v0.5.6
Here is an example of the working python code
Add Job
import asyncio
import redis.asyncio as redis
from bullmq import Queue
r = redis.Redis()
async def main():
queue = Queue('my-queue')
job = await queue.add('my-job', {'foo': 'bar'})
job_id = job.id
job_data = job.data
print(f"Job ID: {job_id}")
print(f"Job Data: {job_data}")
asyncio.run(main())
Get a Job
from asyncio import Future, run
from bullmq import Queue, Worker, Job
async def main():
async def process(job: Job, token: str):
print("Processing job", job.id)
print(job.data)
return "done"
while True:
processing = Future()
worker = Worker("my-queue", process)
worker.on("completed", lambda job, result: processing.set_result(None))
await processing
run(main())
Let me know if there are other such examples, you have created or have better ways to get job and update it’s status
How to reproduce.
Try to run the examples on https://docs.bullmq.io/python/introduction
Relevant log output
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Update introduction.md #2010 — committed to cagejsn/bullmq by cagejsn 2 years ago
- Update introduction.md #2010 — committed to cagejsn/bullmq by cagejsn 2 years ago
Hi, i am starting to use the python version of bullmq. I expanded on the provided example and replaced the while loop with awaiting shutdown event. I thought other people may benefit from this change. See the PR here: https://github.com/taskforcesh/bullmq/pull/2677/files
The documentation is really misleading needs more information in key areas:
tokenis only needed when processing jobs manually. However, if we omit the second parameter (token) from theprocessfunction, the code simply does not work and errors withError processing job process() takes 1 positional argument but 2 were given. This should absolutely be fixed in the example code.If we remove the loop, the worker will never really run or process any jobs. Is the comment false? Should we replace the loop with something else? Shouldn’t the worker itself keep the process alive? The docs would benefit greatly from more information here.
@vraj-fyno not sure what I should look for about this issue. Why don’t you use the example code from the documentation instead of writing your own that does not work?