httsleep
httsleep is a powerful polling library for Python.
Idea
Set your success conditions, set a few alarms, and get polling!
until = {
'status_code': 200,
'jsonpath': [{'expression': 'status', 'value': 'OK'}]
}
alarms = [
{'json': {'status': 'ERROR'}},
{'jsonpath': [{'expression': 'status', 'value': 'UNKNOWN'},
{'expression': 'owner', 'value': 'Chris'}],
'callback': is_job_really_failing},
{'status_code': 404}
]
try:
response = httsleep(
'http://myendpoint/jobs/1', until, alarms=alarms,
max_retries=20)
except Alarm as e:
print "Response was:", e.response
print "Alarm condition that matched was:", e.alarm
Translated into English, this means:
- Poll
http://myendpoint/jobs/1-- at most 20 times -- until- it returns a status code of
200 - AND the
statuskey in its response has the valueOK
- it returns a status code of
- but raise an alarm if
- the
statuskey has the valueERROR - OR the
statuskey has the valueUNKNOWNAND theownerkey has the valueChrisAND the functionis_job_really_dyingreturnsTrue - OR the status code is 404
- the
Documentation
http://httsleep.readthedocs.io/
Installing
pip install httsleep
Testing
pip install -e . pip install -r test-requirements.txt py.test

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
