Skip to content
/ httsleep Public

A python library for polling HTTP endpoints - batteries included!

License

Notifications You must be signed in to change notification settings

kopf/httsleep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e9d1c40 · Nov 4, 2018
Nov 19, 2017
Nov 19, 2017
Nov 19, 2017
Jul 29, 2016
Nov 4, 2018
Nov 4, 2018
Oct 18, 2017
Jul 29, 2016
Sep 2, 2016
Sep 7, 2016
Jul 29, 2016
Jul 31, 2016
Aug 8, 2016
Nov 4, 2018
Jul 31, 2016

Repository files navigation

httsleep

Build Status

Coverage Status

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 status key in its response has the value OK
  • but raise an alarm if
    • the status key has the value ERROR
    • OR the status key has the value UNKNOWN AND the owner key has the value Chris AND the function is_job_really_dying returns True
    • OR the status code is 404

Documentation

http://httsleep.readthedocs.io/

Installing

pip install httsleep

Testing

pip install -e .
pip install -r test-requirements.txt
py.test