Skip to content

Commit 5863db8

Browse files
committed
sentry app install deletion outbox
1 parent 0f5ff01 commit 5863db8

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
from collections.abc import Sequence
22

3-
from sentry.constants import ObjectStatus
43
from sentry.deletions.base import BaseRelation, ModelDeletionTask, ModelRelation
54
from sentry.deletions.defaults.apigrant import ModelApiGrantDeletionTask
65
from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation
7-
from sentry.types.region import RegionMappingNotFound
8-
from sentry.workflow_engine.service.action import action_service
96

107

118
class SentryAppInstallationDeletionTask(ModelDeletionTask[SentryAppInstallation]):
@@ -28,15 +25,3 @@ def get_child_relations(self, instance: SentryAppInstallation) -> list[BaseRelat
2825

2926
def mark_deletion_in_progress(self, instance_list: Sequence[SentryAppInstallation]) -> None:
3027
pass
31-
32-
def delete_instance(self, instance: SentryAppInstallation) -> None:
33-
try:
34-
action_service.update_action_status_for_sentry_app_via_uuid(
35-
organization_id=instance.organization_id,
36-
status=ObjectStatus.DISABLED,
37-
sentry_app_install_uuid=instance.uuid,
38-
)
39-
except RegionMappingNotFound:
40-
pass
41-
42-
return super().delete_instance(instance)

src/sentry/hybridcloud/outbox/category.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class OutboxCategory(IntEnum):
6262

6363
SERVICE_HOOK_UPDATE = 40
6464
SENTRY_APP_DELETE = 41
65+
SENTRY_APP_INSTALLATION_DELETE = 42
6566

6667
@classmethod
6768
def as_choices(cls) -> Sequence[tuple[int, int]]:
@@ -304,6 +305,7 @@ class OutboxScope(IntEnum):
304305
OutboxCategory.SENTRY_APP_UPDATE,
305306
OutboxCategory.SERVICE_HOOK_UPDATE,
306307
OutboxCategory.SENTRY_APP_DELETE,
308+
OutboxCategory.SENTRY_APP_INSTALLATION_DELETE,
307309
},
308310
)
309311
# No longer in use

src/sentry/receivers/outbox/control.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ def process_sentry_app_deletes(
8383
# TODO: also update webhook actions using object identifier (sentry app slug)
8484

8585

86+
@receiver(process_control_outbox, sender=OutboxCategory.SENTRY_APP_INSTALLATION_DELETE)
87+
def process_sentry_app_installation_deletes(
88+
shard_identifier: int,
89+
object_identifier: int,
90+
region_name: str,
91+
payload: Mapping[str, Any],
92+
**kwds: Any,
93+
):
94+
# This function should only be used when the sentry app is being deleted.
95+
# Currently this receiver is only used for deletion.
96+
if options.get("workflow_engine.sentry-app-actions-outbox"):
97+
logger.info(
98+
"sentry_app_installation_delete.update_action_status",
99+
extra={
100+
"region_name": region_name,
101+
"sentry_app_install_uuid": payload["uuid"],
102+
},
103+
)
104+
action_service.update_action_status_for_sentry_app_via_uuid__region(
105+
region_name=region_name,
106+
status=ObjectStatus.DISABLED,
107+
sentry_app_install_uuid=payload["uuid"],
108+
)
109+
110+
86111
@receiver(process_control_outbox, sender=OutboxCategory.API_APPLICATION_UPDATE)
87112
def process_api_application_updates(object_identifier: int, region_name: str, **kwds: Any):
88113
if (

src/sentry/sentry_apps/models/sentry_app_installation.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey
1717
from sentry.db.models.manager.base_query_set import BaseQuerySet
1818
from sentry.db.models.paranoia import ParanoidManager, ParanoidModel
19-
from sentry.hybridcloud.models.outbox import ControlOutboxBase, outbox_context
19+
from sentry.hybridcloud.models.outbox import ControlOutbox, ControlOutboxBase, outbox_context
2020
from sentry.hybridcloud.outbox.base import ReplicatedControlModel
21-
from sentry.hybridcloud.outbox.category import OutboxCategory
21+
from sentry.hybridcloud.outbox.category import OutboxCategory, OutboxScope
2222
from sentry.projects.services.project import RpcProject
2323
from sentry.sentry_apps.services.app.model import RpcSentryAppComponent, RpcSentryAppInstallation
2424
from sentry.sentry_apps.utils.errors import (
2525
SentryAppError,
2626
SentryAppIntegratorError,
2727
SentryAppSentryError,
2828
)
29-
from sentry.types.region import find_regions_for_orgs
29+
from sentry.types.region import find_all_region_names, find_regions_for_orgs
3030

3131
if TYPE_CHECKING:
3232
from sentry.models.project import Project
@@ -141,6 +141,19 @@ def outboxes_for_update(self, shard_identifier: int | None = None) -> list[Contr
141141
# these isn't so important in that case.
142142
return super().outboxes_for_update(shard_identifier=self.api_application_id or 0)
143143

144+
def outboxes_for_delete(self) -> list[ControlOutbox]:
145+
return [
146+
ControlOutbox(
147+
shard_scope=OutboxScope.APP_SCOPE,
148+
shard_identifier=self.id,
149+
object_identifier=self.id,
150+
category=OutboxCategory.SENTRY_APP_INSTALLATION_DELETE,
151+
region_name=region_name,
152+
payload={"uuid": self.uuid},
153+
)
154+
for region_name in find_all_region_names()
155+
]
156+
144157
def prepare_ui_component(
145158
self,
146159
component: SentryAppComponent,

0 commit comments

Comments
 (0)