Skip to content

Instantly share code, notes, and snippets.

@tjcunliffe
Created December 8, 2015 11:51
Show Gist options
  • Save tjcunliffe/ddda20e4a895abd651d0 to your computer and use it in GitHub Desktop.
Save tjcunliffe/ddda20e4a895abd651d0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import logging
import random
from time import sleep
logging.basicConfig(filename='random_delay_middleware_python.log', level=logging.DEBUG)
logging.debug('Random delay middleware is called')
# set delay to random value less than one second
SLEEP_SECS = random.random()
def main():
data = sys.stdin.readlines()
# this is a json string in one line so we are interested in that one line
payload = data[0]
logging.debug("sleeping for %s seconds" % SLEEP_SECS)
sleep(SLEEP_SECS)
# do not modifying payload, returning same one
print(payload)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment