class HttpBinNice: base_uri = "https://httpbin.org" middleware = [retry(max_retries=2, retry_in_between_call_sleep=1), fail(1)] response_as = json_response def get(self): return self.request.get("get")
class HttpBinBad(object): base_uri = "https://httpbin.org" middleware = [retry(5), fail(10)] response_as = json_response def get(self): return self.request.get("get")
from hs_formation import wrap, _CONTEXT from hs_formation.middleware import retry, context_logger, context import structlog def bad_function(ctx): print(ctx) if ctx[_CONTEXT].get("env") == "development": raise Exception("boo hoo") stack = wrap( lambda ctx: bad_function(ctx), middleware=[ context(env="development"), context_logger(structlog.getLogger()), retry(max_retries=2), ], ) # This should always fail, but you should see two retries, and a log # to indicate the context that's been discovered. if __name__ == "__main__": stack({"args": ["hello", "world"]})