|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | import logging
|
| 4 | +from datetime import timedelta |
4 | 5 | from typing import TYPE_CHECKING, Mapping, Optional, Sequence, Tuple, TypedDict, Union
|
5 | 6 |
|
6 | 7 | import sentry_sdk
|
7 | 8 | from django.conf import settings
|
| 9 | +from django.utils import timezone |
8 | 10 |
|
9 | 11 | from sentry import features
|
10 | 12 | from sentry.exceptions import PluginError
|
@@ -595,6 +597,37 @@ def process_rules(job: PostProcessJob) -> None:
|
595 | 597 | return
|
596 | 598 |
|
597 | 599 |
|
| 600 | +def process_code_mappings(job: PostProcessJob) -> None: |
| 601 | + if job["is_reprocessed"]: |
| 602 | + return |
| 603 | + |
| 604 | + from sentry.tasks.derive_code_mappings import derive_code_mappings |
| 605 | + |
| 606 | + try: |
| 607 | + event = job["event"] |
| 608 | + project = event.project |
| 609 | + |
| 610 | + cache_key = f"code-mappings:{project.organization_id}" |
| 611 | + organization_queued = cache.get(cache_key) |
| 612 | + # TODO(snigdha): Change the cache to per-project once we're able to optimize get_trees_for_org. |
| 613 | + # This will only process code mappings one project per org per hour but we can do better. |
| 614 | + if organization_queued is None: |
| 615 | + cache.set(cache_key, True, 3600) |
| 616 | + logger.info( |
| 617 | + f"derive_code_mappings: Events from {project.id} in {project.organization_id} will not have code mapping derivation until {timezone.now() + timedelta(hours=1)}" |
| 618 | + ) |
| 619 | + |
| 620 | + if organization_queued or not features.has( |
| 621 | + "organizations:derive-code-mappings", event.project.organization |
| 622 | + ): |
| 623 | + return |
| 624 | + |
| 625 | + derive_code_mappings.delay(project.id, event.data) |
| 626 | + |
| 627 | + except Exception: |
| 628 | + logger.exception("Failed to set auto-assignment") |
| 629 | + |
| 630 | + |
598 | 631 | def process_commits(job: PostProcessJob) -> None:
|
599 | 632 | if job["is_reprocessed"]:
|
600 | 633 | return
|
@@ -777,6 +810,7 @@ def plugin_post_process_group(plugin_slug, event, **kwargs):
|
777 | 810 | process_service_hooks,
|
778 | 811 | process_resource_change_bounds,
|
779 | 812 | process_plugins,
|
| 813 | + process_code_mappings, |
780 | 814 | process_similarity,
|
781 | 815 | update_existing_attachments,
|
782 | 816 | fire_error_processed,
|
|
0 commit comments