Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Created September 24, 2014 19:50
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/d733e87e1a735d382d6a to your computer and use it in GitHub Desktop.
Save sandeepraju/d733e87e1a735d382d6a to your computer and use it in GitHub Desktop.
A simple SHARQ worker which does a Dequeue request to fetch a job from the SHARQ Server. Requires Python Requests (http://docs.python-requests.org/en/latest/)
import time
import json
import requests
while True:
response = requests.get('http://localhost:8080/dequeue/sms/')
if response.status_code == 200:
# successful dequeue.
payload = json.loads(response.text)['payload']
print payload # process the payload here.
# if the payload processing is success, then mark
# this job as finished using the **Finish** API.
# All jobs that are not marked as finished will
# be re-queued depending on the `job_expire_interval`
# and `job_requeue_interval` in the sharq.conf
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment