Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (31 sloc) 1.33 KB
import requests
import time
import logging
import uuid
import json
logging.basicConfig(format='%(asctime)s: (%(levelname)s) %(name)s - %(message)s', level=logging.INFO)
worker_id = str(uuid.uuid4())"Worker id is %s", worker_id)
while True:
todo = requests.get("http://localhost:8003/queue/example")
if todo.status_code == 404:"Still waiting for provider to come up, waiting 5 seconds...")
todo = todo.json()"todo: %s",todo)
for k in todo.keys():
v = todo[k]
if v["state"] == "pending" and v["task_name"] == "hello_world":"Grabbing %s", k)
grab = requests.put("http://localhost:8003/queue/example/%s" % k, data=json.dumps({"worker_id": worker_id}))
if grab.status_code != 200:
raise Exception, (grab.status_code, grab.text)
v = grab.json()"Hello World with data %s", v["info"])
done = requests.delete("http://localhost:8003/queue/example/%s" % k, data=json.dumps({"worker_id": worker_id}))
if done.status_code != 200:
raise Exception, (grab.status_code, grab.text)"Marked %s as done", k)