-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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