1

I have two files, literally copy-pasted from http://python-rq.org/docs/:

app.py

    from rq import Queue
    from redis import Redis
    from somewhere import count_words_at_url
    import time

    # Tell RQ what Redis connection to use
    redis_conn = Redis()
    q = Queue(connection=redis_conn)  # no args implies the default queue

    print(redis_conn)
    # Delay execution of count_words_at_url('http://nvie.com')
    job = q.enqueue(count_words_at_url, 'http://nvie.com')
    print(job.result)   # => None

    # Now, wait a while, until the worker is finished
    time.sleep(10)
    print(job.result)   # => 889

somewhere.py

import requests
def count_words_at_url(url):
    print("hello?")
    resp = requests.get(url)
    return len(resp.text.split())

I ran app.py , and the output I got was 2 None values, as opposed to a 889 which I'm supposed to get according to the docs.

I'm not sure I understand why this is happening. My timeout is 10 seconds, and it's longer than what's in the doc, so I was expecting the job to have finished working.

What am I doing wrong?

1
  • Isolating, does count_words_at_url('http://nvie.com') return 889 on it's own? Commented Dec 1, 2018 at 7:52

1 Answer 1

1
  1. Is Redis server running?

    service redis-server status

  2. Is rq worker running?

    rq info

if no worker running, then

rq worker # run this under the same directory of your project
18:44:54 RQ worker 'rq:worker:ubuntu.45276' started, version 0.12.0
18:44:54 *** Listening on default...
18:44:54 Cleaning registries for queue: default
  1. replace count_words_at_url with simpler function, such as

    def just_mock(url): time.sleep(5) return "count words for {} is ??".format(url)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.