From fa64e2ef1aa55329e3d77cd55e3519dd5b84f224 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 27 Sep 2024 14:00:46 +0530 Subject: [PATCH] updated ci fail notification logic --- pkg/pipeline/CiHandler.go | 5 ++--- pkg/pipeline/bean/CiPipeline/CiStatus.go | 11 +++++++++++ pkg/workflow/dag/WorkflowDagExecutor.go | 10 +++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 pkg/pipeline/bean/CiPipeline/CiStatus.go diff --git a/pkg/pipeline/CiHandler.go b/pkg/pipeline/CiHandler.go index a9332f79f08..096cdf5f2e1 100644 --- a/pkg/pipeline/CiHandler.go +++ b/pkg/pipeline/CiHandler.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/cdWorkflow" + "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" util3 "github.com/devtron-labs/devtron/pkg/pipeline/util" "io/ioutil" "net/http" @@ -1071,8 +1072,6 @@ func ExtractWorkflowStatus(workflowStatus v1alpha1.WorkflowStatus) (string, stri return workflowName, status, podStatus, message, logLocation, podName } -const CiStageFailErrorCode = 2 - func (impl *CiHandlerImpl) extractPodStatusAndWorkflow(workflowStatus v1alpha1.WorkflowStatus) (string, string, *pipelineConfig.CiWorkflow, error) { workflowName, status, _, message, _, _ := ExtractWorkflowStatus(workflowStatus) if workflowName == "" { @@ -1159,7 +1158,7 @@ func (impl *CiHandlerImpl) UpdateWorkflow(workflowStatus v1alpha1.WorkflowStatus if string(v1alpha1.NodeError) == savedWorkflow.Status || string(v1alpha1.NodeFailed) == savedWorkflow.Status { impl.Logger.Warnw("ci failed for workflow: ", "wfId", savedWorkflow.Id) - if extractErrorCode(savedWorkflow.Message) != CiStageFailErrorCode { + if extractErrorCode(savedWorkflow.Message) != CiPipeline.CiStageFailErrorCode { go impl.WriteCIFailEvent(savedWorkflow) } else { impl.Logger.Infof("Step failed notification received for wfID %d with message %s", savedWorkflow.Id, savedWorkflow.Message) diff --git a/pkg/pipeline/bean/CiPipeline/CiStatus.go b/pkg/pipeline/bean/CiPipeline/CiStatus.go new file mode 100644 index 00000000000..6956cd6ac8a --- /dev/null +++ b/pkg/pipeline/bean/CiPipeline/CiStatus.go @@ -0,0 +1,11 @@ +package CiPipeline + +type CiFailReason string + +func (r CiFailReason) String() string { + return string(r) +} + +const CiFailed CiFailReason = "CI Failed: exit code 1" + +const CiStageFailErrorCode = 2 diff --git a/pkg/workflow/dag/WorkflowDagExecutor.go b/pkg/workflow/dag/WorkflowDagExecutor.go index a9d4d317651..ddaf05faae4 100644 --- a/pkg/workflow/dag/WorkflowDagExecutor.go +++ b/pkg/workflow/dag/WorkflowDagExecutor.go @@ -978,10 +978,14 @@ func (impl *WorkflowDagExecutorImpl) HandleCiStepFailedEvent(ciPipelineId int, r } } impl.asyncRunnable.Execute(customTagServiceRunnableFunc) - notificationServiceRunnableFunc := func() { - impl.WriteCiStepFailedEvent(pipelineModel, request, savedWorkflow) + if request.FailureReason != CiPipeline.CiFailed.String() { + notificationServiceRunnableFunc := func() { + impl.WriteCiStepFailedEvent(pipelineModel, request, savedWorkflow) + } + impl.asyncRunnable.Execute(notificationServiceRunnableFunc) + } else { + // this case has been handled CiHandlerImpl.UpdateWorkflow function. } - impl.asyncRunnable.Execute(notificationServiceRunnableFunc) return nil }