[Python] RQ Worker throwing "ValueError"

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'm attempting to get RQ/RQ-Worker running on my Flask application. I've tried to get it down to a very simple test case. Here's the general idea:

    1. The user visits the /test page. Which triggers a job to be queued and returns the queued job's job_key
    2. The worker (worker.py) processes the queued job.
    3. The user can then visit the /retrieve/<job_key> page to retrieve the result. [This is not shown.]

    The current job is just to add 2 + 2.

    Here is the application code:

    from rq import Queue
    from rq.job import Job

    # import conn from worker.py
    from worker import conn

    app = Flask(__name__)

    q = Queue(connection=conn)

    def add():
    return 2+2

    @app.route('/test')
    def test():
    job = q.enqueue_call(func="add", args=None, result_ttl=5000)
    return job.get_id()

    if __name__ == "__main__":
    app.run()


    The worker.py source code looks like this:

    from redis import StrictRedis
    from rq import Worker, Queue, Connection

    listen = ['default']
    redis_url = 'redis://localhost:6379'
    conn = StrictRedis.from_url(redis_url)
    if __name__ == "__main__":
    with Connection(conn):
    worker = Worker(list(map(Queue, listen)))
    worker.work()


    To my knowledge, the application code isn't the issue. I can visit the /test page which will enqueue the job. However, once I run the worker, I get the following error:

    Traceback (most recent call last):
    File "/home/<>/dev/sched/venv/lib/python3.5/site-packages/rq/worker.py", line 588, in perform_job
    rv = job.perform()
    File "/home/<>/dev/sched/venv/lib/python3.5/site-packages/rq/job.py", line 498, in perform
    self._result = self.func(*self.args, **self.kwargs)
    File "/home/<>/dev/sched/venv/lib/python3.5/site-packages/rq/job.py", line 206, in func
    return import_attribute(self.func_name)
    File "/home/<>/dev/sched/venv/lib/python3.5/site-packages/rq/utils.py", line 149, in import_attribute
    module_name, attribute = name.rsplit('.', 1)
    ValueError: not enough values to unpack (expected 2, got 1)


    I feel like the line:

    worker = Worker(list(map(Queue, listen)))


    is the problem just b/c of the nature of the error, but I have no idea how to fix it. Especially b/c I've seen other projects that seem to use the exact same worker source code.

    My technology stack is:

    1. Flask (0.11.1)
    2. Redis (2.10.5)
    3. RQ (0.6.0)
    4. RQ-Worker (0.0.1)

    EDIT:

    Beginning to think this is a bug. Check out this issue ticket in RQ's source: issue #531.

    Continue reading...

Compartilhe esta Página