Created
December 8, 2015 11:51
-
-
Save tjcunliffe/ddda20e4a895abd651d0 to your computer and use it in GitHub Desktop.
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
#!/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