99from django .db .models import Q
1010
1111from sentry import features
12- from sentry .db .models .manager .base_query_set import BaseQuerySet
1312from sentry .models .activity import Activity
1413from sentry .models .environment import Environment
1514from sentry .services .eventstore .models import GroupEvent
3433)
3534from sentry .workflow_engine .processors .detector import get_detector_by_event
3635from sentry .workflow_engine .processors .workflow_fire_history import create_workflow_fire_histories
37- from sentry .workflow_engine .types import WorkflowEventData , WorkflowNotProcessable
36+ from sentry .workflow_engine .types import WorkflowEvaluation , WorkflowEventData
3837from sentry .workflow_engine .utils import log_context , scopedstats
3938from sentry .workflow_engine .utils .metrics import metrics_incr
4039
@@ -465,7 +464,7 @@ def process_workflows(
465464 event_data : WorkflowEventData ,
466465 event_start_time : datetime ,
467466 detector : Detector | None = None ,
468- ) -> tuple [ set [ Workflow ], BaseQuerySet [ Action ]] | WorkflowNotProcessable :
467+ ) -> WorkflowEvaluation :
469468 """
470469 This method will get the detector based on the event, and then gather the associated workflows.
471470 Next, it will evaluate the "when" (or trigger) conditions for each workflow, if the conditions are met,
@@ -479,7 +478,7 @@ def process_workflows(
479478 fire_actions ,
480479 )
481480
482- # This dictionary stores the data for WorkflowNotProcessable
481+ # This dictionary stores the data for WorkflowEvaluation
483482 # and is eventually unpacked to pass into the frozen dataclass
484483 # TODO -- should this be a workflow event context data instead?
485484 extra_data : dict [str , Any ] = {
@@ -504,7 +503,8 @@ def process_workflows(
504503 )
505504 )
506505 except Detector .DoesNotExist :
507- return WorkflowNotProcessable (
506+ return WorkflowEvaluation (
507+ tainted = True ,
508508 message = "No Detectors associated with the issue were found" ,
509509 ** extra_data ,
510510 )
@@ -523,7 +523,8 @@ def process_workflows(
523523 )
524524 )
525525 except Environment .DoesNotExist :
526- return WorkflowNotProcessable (
526+ return WorkflowEvaluation (
527+ tainted = True ,
527528 message = "Environment for event not found" ,
528529 ** extra_data ,
529530 )
@@ -535,7 +536,8 @@ def process_workflows(
535536 extra_data ["workflows" ] = workflows
536537
537538 if not workflows :
538- return WorkflowNotProcessable (
539+ return WorkflowEvaluation (
540+ tainted = True ,
539541 message = "No workflows are associated with the detector in the event" ,
540542 ** extra_data ,
541543 )
@@ -547,7 +549,8 @@ def process_workflows(
547549 extra_data ["triggered_workflows" ] = triggered_workflows
548550
549551 if not triggered_workflows and not queue_items_by_workflow_id :
550- return WorkflowNotProcessable (
552+ return WorkflowEvaluation (
553+ tainted = True ,
551554 message = "No items were triggered or queued for slow evaluation" ,
552555 ** extra_data ,
553556 )
@@ -570,7 +573,8 @@ def process_workflows(
570573 }
571574
572575 if not actions :
573- return WorkflowNotProcessable (
576+ return WorkflowEvaluation (
577+ tainted = True ,
574578 message = "No actions to evaluate; filtered or not triggered" ,
575579 ** extra_data ,
576580 )
@@ -586,18 +590,18 @@ def process_workflows(
586590 )
587591
588592 fire_actions (actions , detector , event_data )
589- return triggered_workflows , actions
593+ return WorkflowEvaluation ( tainted = False , ** extra_data )
590594
591595
592596def process_workflows_with_logs (
593597 batch_client : DelayedWorkflowClient ,
594598 event_data : WorkflowEventData ,
595599 event_start_time : datetime ,
596600 detector : Detector | None = None ,
597- ) -> None :
601+ ) -> WorkflowEvaluation :
598602 """
599603 This method is used to create improved logging for `process_workflows`,
600- where we can capture the `WorkflowNotProcessable ` results, and log them.
604+ where we can capture the `WorkflowEvaluation ` results, and log them.
601605
602606 This should create a log for each issue, so we can determine why a workflow
603607 did or did not trigger.
@@ -608,7 +612,7 @@ def process_workflows_with_logs(
608612
609613 evaluation = process_workflows (batch_client , event_data , event_start_time , detector )
610614
611- if isinstance (evaluation , WorkflowNotProcessable ):
615+ if isinstance (evaluation , WorkflowEvaluation ):
612616 # Attempted to evaluate, but no actions were triggered.
613617
614618 if evaluation .triggered_workflows is None :
@@ -621,8 +625,6 @@ def process_workflows_with_logs(
621625 logger .info ("process_workflows.evaluation.workflow.triggered" , extra = asdict (evaluation ))
622626 else :
623627 # Workflow was fully processed, and actions were triggered
624- workflows , actions = evaluation
625- logger .info (
626- "process_workflows.evaluation.actions.triggered" ,
627- extra = {"workflows" : workflows , "actions" : actions },
628- )
628+ logger .info ("process_workflows.evaluation.actions.triggered" , extra = asdict (evaluation ))
629+
630+ return evaluation
0 commit comments