Skip to content

Commit d63de2a

Browse files
authored
fix: invalid runner status (#5189)
* wip: updating wf status * updating status
1 parent 0269dcd commit d63de2a

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

pkg/eventProcessor/in/WorkflowEventProcessorService.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func (impl *WorkflowEventProcessorImpl) SubscribeCDStageCompleteEvent() error {
152152
impl.logger.Errorw("could not get wf runner", "err", err)
153153
return
154154
}
155+
156+
if wfr.Status != string(v1alpha1.NodeSucceeded) {
157+
impl.logger.Debugw("event received from ci runner, updating workflow runner status as succeeded", "savedWorkflowRunnerId", wfr.Id, "oldStatus", wfr.Status, "podStatus", wfr.PodStatus)
158+
err = impl.cdWorkflowRunnerService.UpdateWfrStatus(wfr, string(v1alpha1.NodeSucceeded), 1)
159+
if err != nil {
160+
impl.logger.Errorw("update cd-wf-runner failed for id ", "cdWfrId", wfr.Id, "err", err)
161+
return
162+
}
163+
}
164+
155165
triggerContext := bean5.TriggerContext{
156166
ReferenceId: pointer.String(msg.MsgId),
157167
}

pkg/workflow/cd/CdWorkflowRunnerService.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
2323
"github.com/go-pg/pg"
2424
"go.uber.org/zap"
25+
"time"
2526
)
2627

2728
type CdWorkflowRunnerService interface {
2829
FindWorkflowRunnerById(wfrId int) (*bean.CdWorkflowRunnerDto, error)
2930
CheckIfWfrLatest(wfrId, pipelineId int) (isLatest bool, err error)
31+
UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error
3032
}
3133

3234
type CdWorkflowRunnerServiceImpl struct {
@@ -60,3 +62,16 @@ func (impl *CdWorkflowRunnerServiceImpl) CheckIfWfrLatest(wfrId, pipelineId int)
6062
}
6163
return isLatest, nil
6264
}
65+
66+
func (impl *CdWorkflowRunnerServiceImpl) UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error {
67+
runnerDbObj := adapter.ConvertCdWorkflowRunnerDtoToDbObj(dto)
68+
runnerDbObj.Status = status
69+
runnerDbObj.UpdatedBy = int32(updatedBy)
70+
runnerDbObj.UpdatedOn = time.Now()
71+
err := impl.cdWorkflowRepository.UpdateWorkFlowRunner(runnerDbObj)
72+
if err != nil {
73+
impl.logger.Errorw("error in updating runner status in db", "runnerId", runnerDbObj.Id, "err", err)
74+
return err
75+
}
76+
return nil
77+
}

pkg/workflow/cd/adapter/adapter.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,26 @@ func ConvertCdWorkflowDtoToDbObj(dto *bean.CdWorkflowDto) *pipelineConfig.CdWork
6262
},
6363
}
6464
}
65+
66+
func ConvertCdWorkflowRunnerDtoToDbObj(dto *bean.CdWorkflowRunnerDto) *pipelineConfig.CdWorkflowRunner {
67+
return &pipelineConfig.CdWorkflowRunner{
68+
Id: dto.Id,
69+
Name: dto.Name,
70+
WorkflowType: dto.WorkflowType,
71+
ExecutorType: dto.ExecutorType,
72+
Status: dto.Status,
73+
PodStatus: dto.PodStatus,
74+
Message: dto.Message,
75+
StartedOn: dto.StartedOn,
76+
FinishedOn: dto.FinishedOn,
77+
Namespace: dto.Namespace,
78+
LogLocation: dto.LogLocation,
79+
TriggeredBy: dto.TriggeredBy,
80+
CdWorkflowId: dto.CdWorkflowId,
81+
PodName: dto.PodName,
82+
BlobStorageEnabled: dto.BlobStorageEnabled,
83+
RefCdWorkflowRunnerId: dto.RefCdWorkflowRunnerId,
84+
ImagePathReservationIds: dto.ImagePathReservationIds,
85+
ReferenceId: dto.ReferenceId,
86+
}
87+
}

0 commit comments

Comments
 (0)