Instantly share code, notes, and snippets.

@sandeepraju / Secret
Created Sep 24, 2014

What would you like to do?
A simple SHARQ worker which does a Dequeue request to fetch a job from the SHARQ Server. Requires Python Requests (
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