Skip to content

Commit

Permalink
updated ci fail notification logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-exp committed Sep 27, 2024
1 parent 805f628 commit fa64e2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 2 additions & 3 deletions pkg/pipeline/CiHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pkg/pipeline/bean/CiPipeline/CiStatus.go
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions pkg/workflow/dag/WorkflowDagExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fa64e2e

Please sign in to comment.