Created
April 7, 2020 15:08
-
-
Save groovecoder/8783bff51b8ef62fde718b2968075cdd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def time_if_enabled(func): | |
def timing_decorator(name): | |
def func_wrapper(name): | |
ctx_manager = (request.timings(name) if settings.STATSD_ENABLED | |
else contextlib.suppress()) | |
with ctx_manager: | |
func() | |
return func_wrapper | |
return timing_decorator | |
@time_if_enabled('socketlabs_client') | |
def _get_socketlabs_client(): | |
return SocketLabsClient( | |
settings.SOCKETLABS_SERVER_ID, settings.SOCKETLABS_API_KEY | |
) | |
@time_if_enabled('socketlabs_client_send') | |
def _socketlabs_send(sl_client, sl_message): | |
try: | |
return sl_client.send(sl_message) | |
except Exception: | |
logger.exception("exception during sl send") | |
return HttpResponse("Internal Server Error", status=500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment