33import sys
44import time
55
6+ try :
7+ from typing import cast
8+ except ImportError :
9+ cast = lambda _ , o : o
10+
611from sentry_sdk .api import continue_trace
712from sentry_sdk .consts import OP
813from sentry_sdk ._compat import reraise
3136 from typing import Union
3237
3338 from sentry_sdk .tracing import Span
34- from sentry_sdk ._types import EventProcessor , Event , Hint , ExcInfo
39+ from sentry_sdk ._types import (
40+ EventProcessor ,
41+ Event ,
42+ Hint ,
43+ ExcInfo ,
44+ MonitorConfig ,
45+ MonitorConfigScheduleType ,
46+ MonitorConfigScheduleUnit ,
47+ )
3548
3649 F = TypeVar ("F" , bound = Callable [..., Any ])
3750
@@ -416,7 +429,7 @@ def _get_headers(task):
416429
417430
418431def _get_humanized_interval (seconds ):
419- # type: (float) -> Tuple[int, str ]
432+ # type: (float) -> Tuple[int, MonitorConfigScheduleUnit ]
420433 TIME_UNITS = ( # noqa: N806
421434 ("day" , 60 * 60 * 24.0 ),
422435 ("hour" , 60 * 60.0 ),
@@ -427,17 +440,17 @@ def _get_humanized_interval(seconds):
427440 for unit , divider in TIME_UNITS :
428441 if seconds >= divider :
429442 interval = int (seconds / divider )
430- return (interval , unit )
443+ return (interval , cast ( "MonitorConfigScheduleUnit" , unit ) )
431444
432445 return (int (seconds ), "second" )
433446
434447
435448def _get_monitor_config (celery_schedule , app , monitor_name ):
436- # type: (Any, Celery, str) -> Dict[str, Any]
437- monitor_config = {} # type: Dict[str, Any]
438- schedule_type = None # type: Optional[str ]
449+ # type: (Any, Celery, str) -> MonitorConfig
450+ monitor_config = {} # type: MonitorConfig
451+ schedule_type = None # type: Optional[MonitorConfigScheduleType ]
439452 schedule_value = None # type: Optional[Union[str, int]]
440- schedule_unit = None # type: Optional[str ]
453+ schedule_unit = None # type: Optional[MonitorConfigScheduleUnit ]
441454
442455 if isinstance (celery_schedule , crontab ):
443456 schedule_type = "crontab"
0 commit comments