Skip to content

Commit

Permalink
Updates to the models based on discussions throughout the week.
Browse files Browse the repository at this point in the history
- Changed workflow_action to be action, and more generic. will use this
  to emit events on detectors or send notifications in workflows
- Created lookup tables; detector_workflow and
  workflow_data_condition_group
- Updated detector and workflow models to represent new design
  • Loading branch information
saponifi3d committed Sep 20, 2024
1 parent a80d29a commit a53b0ef
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.db import models

from sentry.backup.scopes import RelocationScope
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model, sane_repr
from sentry.db.models import DefaultFieldsModel, region_silo_model, sane_repr


@region_silo_model
class WorkflowAction(DefaultFieldsModel):
class Action(DefaultFieldsModel):
"""
A workflow action is an action to be taken as part of a workflow.
These will be executed in order as part of a workflow.
Expand All @@ -14,11 +14,11 @@ class WorkflowAction(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Organization
__repr__ = sane_repr("workflow_id", "type")

# TODO (@saponifi3d): Don't hardcode these values
class Type(models.TextChoices):
NOTIFICATION = "SendNotificationAction"
Notification = "SendNotificationAction"

required = models.BooleanField(default=False)
workflow = FlexibleForeignKey("workflow_engine.Workflow")
type = models.TextField(choices=Type.choices)
data = models.JSONField(default=dict)
data_condition_group = models.ForeignKey(
Expand Down
9 changes: 7 additions & 2 deletions src/sentry/workflow_engine/models/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class Detector(DefaultFieldsModel, OwnerModel):
organization = FlexibleForeignKey("sentry.Organization")
name = models.CharField(max_length=200)
data_sources = models.ManyToManyField("workflow_engine.DataSource", through=DataSourceDetector)
data_condition_group = models.ForeignKey(
"workflow_engine.DataConditionGroup", on_delete=models.CASCADE, blank=True, null=True

condition_group = models.ForeignKey(
"workflow_engine.DataConditionGroup",
on_delete=models.CASCADE,
blank=True,
null=True,
unique=True,
)

class Meta(OwnerModel.Meta):
Expand Down
10 changes: 10 additions & 0 deletions src/sentry/workflow_engine/models/detector_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from sentry.backup.scopes import RelocationScope
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model


@region_silo_model
class DetectorWorkflow(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Organization

detector = FlexibleForeignKey("workflow_engine.Detector")
workflow = FlexibleForeignKey("workflow_engine.Workflow")
5 changes: 5 additions & 0 deletions src/sentry/workflow_engine/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from sentry.backup.scopes import RelocationScope
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model, sane_repr

from .data_condition_group import DataConditionGroup


@region_silo_model
class Workflow(DefaultFieldsModel):
Expand All @@ -15,6 +17,9 @@ class Workflow(DefaultFieldsModel):
name = models.CharField(max_length=200)
organization = FlexibleForeignKey("sentry.Organization")

# Required as the 'when' condition for the workflow
condition_group = FlexibleForeignKey(DataConditionGroup, on_delete=models.CASCADE)

__repr__ = sane_repr("name", "organization_id")

class Meta:
Expand Down
10 changes: 10 additions & 0 deletions src/sentry/workflow_engine/models/workflow_data_condition_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from sentry.backup.scopes import RelocationScope
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model


@region_silo_model
class WorkflowDataConditionGroup(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Organization

workflow = FlexibleForeignKey("workflow_engine.Workflow")
condition_group = FlexibleForeignKey("workflow_engine.WorkflowDataCondition", unique=True)

0 comments on commit a53b0ef

Please sign in to comment.