|
1 | 1 | import sys |
2 | 2 | import time |
3 | | -from datetime import timedelta, timezone |
| 3 | +from functools import wraps |
4 | 4 |
|
5 | 5 | import sentry_sdk |
6 | 6 | from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS |
7 | 7 | from sentry_sdk.crons import monitor |
| 8 | +from sentry_sdk.crons.utils import _get_timezone_name |
8 | 9 | from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version |
9 | 10 | from sentry_sdk.integrations.logging import ignore_logger |
10 | 11 | from sentry_sdk.scope import should_send_default_pii |
@@ -221,6 +222,7 @@ def event_processor(event: "Event", hint: "Hint") -> "Optional[Event]": |
221 | 222 |
|
222 | 223 |
|
223 | 224 | def _wrap_coroutine(name: str, coroutine: "WorkerCoroutine") -> "WorkerCoroutine": |
| 225 | + @wraps(coroutine) |
224 | 226 | async def _sentry_coroutine( |
225 | 227 | ctx: "Dict[Any, Any]", *args: "Any", **kwargs: "Any" |
226 | 228 | ) -> "Any": |
@@ -326,6 +328,9 @@ def _monitor_cron_job( |
326 | 328 | return |
327 | 329 | cron_job._sentry_monitored = True |
328 | 330 |
|
| 331 | + if getattr(cron_job.coroutine, "_sentry_monitored", False): |
| 332 | + return |
| 333 | + |
329 | 334 | # arq names cron jobs "cron:<function name>" by default. |
330 | 335 | monitor_slug = cron_job.name |
331 | 336 | if monitor_slug.startswith("cron:"): |
@@ -393,35 +398,23 @@ def _get_crontab(cron_job: "CronJob") -> "Optional[str]": |
393 | 398 | return " ".join(fields) # type: ignore[arg-type] |
394 | 399 |
|
395 | 400 |
|
396 | | -def _get_timezone_name(worker: "Worker") -> "Optional[str]": |
| 401 | +def _get_worker_timezone_name(worker: "Worker") -> "Optional[str]": |
397 | 402 | tz = getattr(worker, "timezone", None) |
398 | 403 | if tz is None: |
399 | 404 | # Before arq 0.25, cron jobs ran in naive local time. |
400 | 405 | if time.timezone == 0 and (not time.daylight or time.altzone == 0): |
401 | 406 | return "UTC" |
402 | 407 | return None |
403 | 408 |
|
404 | | - # zoneinfo and pytz |
405 | | - name = getattr(tz, "key", None) or getattr(tz, "zone", None) |
406 | | - if isinstance(name, str): |
407 | | - return name |
408 | | - |
409 | 409 | # arq defaults to the system's fixed UTC offset at startup. |
410 | | - if isinstance(tz, timezone): |
411 | | - offset = tz.utcoffset(None) |
412 | | - if offset % timedelta(hours=1): |
413 | | - return None |
414 | | - hours = offset // timedelta(hours=1) |
415 | | - return "Etc/GMT%+d" % -hours if hours else "UTC" |
416 | | - |
417 | | - return None |
| 410 | + return _get_timezone_name(tz) |
418 | 411 |
|
419 | 412 |
|
420 | 413 | def _get_monitor_config( |
421 | 414 | cron_job: "CronJob", worker: "Worker" |
422 | 415 | ) -> "Optional[MonitorConfig]": |
423 | 416 | crontab = _get_crontab(cron_job) |
424 | | - timezone_name = _get_timezone_name(worker) |
| 417 | + timezone_name = _get_worker_timezone_name(worker) |
425 | 418 | if crontab is None or timezone_name is None: |
426 | 419 | return None |
427 | 420 | return { |
|
0 commit comments