Skip to content

Commit 281e26b

Browse files
authored
feat(code-mappings): Add code mappings task to post process (getsentry#40882)
Add a new task to post process to derive code mappings for a single event per project per hour. FIXES WOR-2356
1 parent a2cd93d commit 281e26b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/sentry/tasks/post_process.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

33
import logging
4+
from datetime import timedelta
45
from typing import TYPE_CHECKING, Mapping, Optional, Sequence, Tuple, TypedDict, Union
56

67
import sentry_sdk
78
from django.conf import settings
9+
from django.utils import timezone
810

911
from sentry import features
1012
from sentry.exceptions import PluginError
@@ -595,6 +597,37 @@ def process_rules(job: PostProcessJob) -> None:
595597
return
596598

597599

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+
598631
def process_commits(job: PostProcessJob) -> None:
599632
if job["is_reprocessed"]:
600633
return
@@ -777,6 +810,7 @@ def plugin_post_process_group(plugin_slug, event, **kwargs):
777810
process_service_hooks,
778811
process_resource_change_bounds,
779812
process_plugins,
813+
process_code_mappings,
780814
process_similarity,
781815
update_existing_attachments,
782816
fire_error_processed,

0 commit comments

Comments
 (0)