Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created April 2, 2020 06:00
Show Gist options
  • Select an option

  • Save AntiKnot/b033dc1b755af93d1684405f3ec4a567 to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/b033dc1b755af93d1684405f3ec4a567 to your computer and use it in GitHub Desktop.
python rq demo
from flask import Flask
from rq import Queue
from rq.job import Job
# -----
from redis import Redis
from rq import Worker, Queue, Connection
conn = Redis()
# -----
app = Flask(__name__)
q = Queue(connection=conn)
@app.route('/')
def index():
return "index"
@app.route('/work')
def work():
job = q.enqueue(foo, n=3)
return job.get_id()
@app.route("/results/<job_key>", methods=['GET'])
def get_results(job_key):
job = Job.fetch(job_key, connection=conn)
if job.is_finished:
return str(job.result), 200
else:
return "Nay!", 202
if __name__ == '__main__':
app.run(host='localhost', port='8001')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment