Skip to content

Instantly share code, notes, and snippets.

@cra
Created May 28, 2022 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cra/f9369616c0f71ca471d192f6573badf0 to your computer and use it in GitHub Desktop.
Save cra/f9369616c0f71ca471d192f6573badf0 to your computer and use it in GitHub Desktop.
  1. Install rq: pip install rq
  2. Run redis docker run -p 6379:6379 redis
  3. Run worker rq worker
  4. Run submit script python submit.py

More info: https://python-rq.org/docs/

import requests
def count_words_at_url(url):
resp = requests.get(url)
return len(resp.text.split())
import time
from redis import Redis
from rq import Queue
from my_module import count_words_at_url
if __name__ == '__main__':
q = Queue(connection=Redis())
job = q.enqueue(count_words_at_url, 'http://nvie.com')
while job.result is None:
print(".", end='')
time.sleep(1)
print(job.result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment