Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Created September 25, 2014 06:38
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 sandeepraju/3da0ad035aa9bf5504b1 to your computer and use it in GitHub Desktop.
Save sandeepraju/3da0ad035aa9bf5504b1 to your computer and use it in GitHub Desktop.
A simple complete SHARQ worker which does a Dequeue request to fetch a job and Finish request to mark it as successfully complete. Requires Python Requests (http://docs.python-requests.org/en/latest/)
import time
import json
import requests
while True:
# dequeue the job from the queue of type `sms`
try:
response = requests.get('http://localhost:8080/dequeue/sms/')
if response.status_code == 200:
# successful dequeue.
r = json.loads(response.text)
print r['payload'] # process the payload here.
queue_id = r['queue_id']
job_id = r['job_id']
# mark the job as completed successfully by
# sending a finish request.
requests.post(
'http://localhost:8080/finish/sms/%s/%s/' % (queue_id, job_id))
elif response.status_code == 404:
# no job found (either queue is empty or none
# of the jobs are ready yet).
time.sleep(1) # wait for a second before retrying if needed.
except Exception as e:
print "Something went wrong!"
time.sleep(5) # retry after 5 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment