-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crons): Make
monitor
async friendly (#2912)
- Loading branch information
1 parent
6c2eb53
commit b742c45
Showing
6 changed files
with
254 additions
and
55 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from functools import wraps | ||
from inspect import iscoroutinefunction | ||
|
||
from sentry_sdk._types import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import ( | ||
Awaitable, | ||
Callable, | ||
ParamSpec, | ||
TypeVar, | ||
Union, | ||
) | ||
|
||
P = ParamSpec("P") | ||
R = TypeVar("R") | ||
|
||
|
||
class MonitorMixin: | ||
def __call__(self, fn): | ||
# type: (Callable[P, R]) -> Callable[P, Union[R, Awaitable[R]]] | ||
if iscoroutinefunction(fn): | ||
|
||
@wraps(fn) | ||
async def inner(*args: "P.args", **kwargs: "P.kwargs"): | ||
# type: (...) -> R | ||
with self: # type: ignore[attr-defined] | ||
return await fn(*args, **kwargs) | ||
|
||
else: | ||
|
||
@wraps(fn) | ||
def inner(*args: "P.args", **kwargs: "P.kwargs"): | ||
# type: (...) -> R | ||
with self: # type: ignore[attr-defined] | ||
return fn(*args, **kwargs) | ||
|
||
return inner |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from functools import wraps | ||
|
||
from sentry_sdk._types import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any, Callable, ParamSpec, TypeVar | ||
|
||
P = ParamSpec("P") | ||
R = TypeVar("R") | ||
|
||
|
||
class MonitorMixin: | ||
def __call__(self, fn): | ||
# type: (Callable[P, R]) -> Callable[P, R] | ||
@wraps(fn) | ||
def inner(*args, **kwargs): | ||
# type: (Any, Any) -> Any | ||
with self: # type: ignore[attr-defined] | ||
return fn(*args, **kwargs) | ||
|
||
return inner |
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
Empty file.
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
Oops, something went wrong.