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

https://docs.bullmq.io/python/introduction

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

Most upvoted comments

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:

  • It might very well be that token is only needed when processing jobs manually. However, if we omit the second parameter (token) from the process function, the code simply does not work and errors with Error processing job process() takes 1 positional argument but 2 were given. This should absolutely be fixed in the example code.
  • How do we keep the worker running? Screenshot 2023-09-27 at 12 44 52

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?