diff --git a/pkg/eventProcessor/in/WorkflowEventProcessorService.go b/pkg/eventProcessor/in/WorkflowEventProcessorService.go index 850aad6d0c..27400029ca 100644 --- a/pkg/eventProcessor/in/WorkflowEventProcessorService.go +++ b/pkg/eventProcessor/in/WorkflowEventProcessorService.go @@ -152,6 +152,16 @@ func (impl *WorkflowEventProcessorImpl) SubscribeCDStageCompleteEvent() error { impl.logger.Errorw("could not get wf runner", "err", err) return } + + if wfr.Status != string(v1alpha1.NodeSucceeded) { + impl.logger.Debugw("event received from ci runner, updating workflow runner status as succeeded", "savedWorkflowRunnerId", wfr.Id, "oldStatus", wfr.Status, "podStatus", wfr.PodStatus) + err = impl.cdWorkflowRunnerService.UpdateWfrStatus(wfr, string(v1alpha1.NodeSucceeded), 1) + if err != nil { + impl.logger.Errorw("update cd-wf-runner failed for id ", "cdWfrId", wfr.Id, "err", err) + return + } + } + triggerContext := bean5.TriggerContext{ ReferenceId: pointer.String(msg.MsgId), } diff --git a/pkg/workflow/cd/CdWorkflowRunnerService.go b/pkg/workflow/cd/CdWorkflowRunnerService.go index 91ac4c0975..23fc0c177f 100644 --- a/pkg/workflow/cd/CdWorkflowRunnerService.go +++ b/pkg/workflow/cd/CdWorkflowRunnerService.go @@ -22,11 +22,13 @@ import ( "github.com/devtron-labs/devtron/pkg/workflow/cd/bean" "github.com/go-pg/pg" "go.uber.org/zap" + "time" ) type CdWorkflowRunnerService interface { FindWorkflowRunnerById(wfrId int) (*bean.CdWorkflowRunnerDto, error) CheckIfWfrLatest(wfrId, pipelineId int) (isLatest bool, err error) + UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error } type CdWorkflowRunnerServiceImpl struct { @@ -60,3 +62,16 @@ func (impl *CdWorkflowRunnerServiceImpl) CheckIfWfrLatest(wfrId, pipelineId int) } return isLatest, nil } + +func (impl *CdWorkflowRunnerServiceImpl) UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error { + runnerDbObj := adapter.ConvertCdWorkflowRunnerDtoToDbObj(dto) + runnerDbObj.Status = status + runnerDbObj.UpdatedBy = int32(updatedBy) + runnerDbObj.UpdatedOn = time.Now() + err := impl.cdWorkflowRepository.UpdateWorkFlowRunner(runnerDbObj) + if err != nil { + impl.logger.Errorw("error in updating runner status in db", "runnerId", runnerDbObj.Id, "err", err) + return err + } + return nil +} diff --git a/pkg/workflow/cd/adapter/adapter.go b/pkg/workflow/cd/adapter/adapter.go index a86323b4e0..5e2dc81017 100644 --- a/pkg/workflow/cd/adapter/adapter.go +++ b/pkg/workflow/cd/adapter/adapter.go @@ -62,3 +62,26 @@ func ConvertCdWorkflowDtoToDbObj(dto *bean.CdWorkflowDto) *pipelineConfig.CdWork }, } } + +func ConvertCdWorkflowRunnerDtoToDbObj(dto *bean.CdWorkflowRunnerDto) *pipelineConfig.CdWorkflowRunner { + return &pipelineConfig.CdWorkflowRunner{ + Id: dto.Id, + Name: dto.Name, + WorkflowType: dto.WorkflowType, + ExecutorType: dto.ExecutorType, + Status: dto.Status, + PodStatus: dto.PodStatus, + Message: dto.Message, + StartedOn: dto.StartedOn, + FinishedOn: dto.FinishedOn, + Namespace: dto.Namespace, + LogLocation: dto.LogLocation, + TriggeredBy: dto.TriggeredBy, + CdWorkflowId: dto.CdWorkflowId, + PodName: dto.PodName, + BlobStorageEnabled: dto.BlobStorageEnabled, + RefCdWorkflowRunnerId: dto.RefCdWorkflowRunnerId, + ImagePathReservationIds: dto.ImagePathReservationIds, + ReferenceId: dto.ReferenceId, + } +}