1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add sentry_async_wrap decorator

This commit is contained in:
Steffo 2020-04-11 00:56:05 +02:00
parent 76899d6deb
commit d9f4eebb2b
2 changed files with 15 additions and 1 deletions

View file

@ -3,7 +3,7 @@ from .sleep_until import sleep_until
from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat
from .urluuid import to_urluuid, from_urluuid from .urluuid import to_urluuid, from_urluuid
from .multilock import MultiLock from .multilock import MultiLock
from .sentry import init_sentry, sentry_exc, sentry_wrap from .sentry import init_sentry, sentry_exc, sentry_wrap, sentry_async_wrap
from .log import init_logging from .log import init_logging
from .royaltyping import JSON from .royaltyping import JSON
@ -21,6 +21,7 @@ __all__ = [
"init_sentry", "init_sentry",
"sentry_exc", "sentry_exc",
"sentry_wrap", "sentry_wrap",
"sentry_async_wrap",
"init_logging", "init_logging",
"JSON", "JSON",
] ]

View file

@ -59,3 +59,16 @@ def sentry_wrap(level: str = "ERROR"):
raise raise
return new_func return new_func
return decorator return decorator
def sentry_async_wrap(level: str = "ERROR"):
def decorator(func: Callable):
@functools.wraps(func)
async def new_func(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as exc:
sentry_exc(exc=exc, level=level)
raise
return new_func
return decorator