Skip to content

Commit 6ecb09b

Browse files
committed
Remove legacy CI/CD workflow status fetching methods and streamline integration with WorkflowStatusLatestService. Update CiHandlerImpl references and clean up unused code.
1 parent 58895c6 commit 6ecb09b

File tree

3 files changed

+51
-259
lines changed

3 files changed

+51
-259
lines changed

pkg/pipeline/CiHandler.go

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/devtron-labs/devtron/pkg/pipeline/adapter"
3131
"github.com/devtron-labs/devtron/pkg/pipeline/constants"
3232
"github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus"
33+
"github.com/devtron-labs/devtron/pkg/workflow/workflowStatusLatest"
3334
"regexp"
3435
"slices"
3536
"strconv"
@@ -77,59 +78,59 @@ type CiHandler interface {
7778
}
7879

7980
type CiHandlerImpl struct {
80-
Logger *zap.SugaredLogger
81-
ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository
82-
ciService CiService
83-
gitSensorClient gitSensor.Client
84-
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
85-
ciArtifactRepository repository.CiArtifactRepository
86-
userService user.UserService
87-
eventClient client.EventClient
88-
eventFactory client.EventFactory
89-
ciPipelineRepository pipelineConfig.CiPipelineRepository
90-
appListingRepository repository.AppListingRepository
91-
cdPipelineRepository pipelineConfig.PipelineRepository
92-
enforcerUtil rbac.EnforcerUtil
93-
resourceGroupService resourceGroup.ResourceGroupService
94-
envRepository repository2.EnvironmentRepository
95-
imageTaggingService imageTagging.ImageTaggingService
96-
customTagService CustomTagService
97-
appWorkflowRepository appWorkflow.AppWorkflowRepository
98-
config *types.CiConfig
99-
k8sCommonService k8sPkg.K8sCommonService
100-
workFlowStageStatusService workflowStatus.WorkFlowStageStatusService
101-
workflowStatusLatestRepository pipelineConfig.WorkflowStatusLatestRepository
81+
Logger *zap.SugaredLogger
82+
ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository
83+
ciService CiService
84+
gitSensorClient gitSensor.Client
85+
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
86+
ciArtifactRepository repository.CiArtifactRepository
87+
userService user.UserService
88+
eventClient client.EventClient
89+
eventFactory client.EventFactory
90+
ciPipelineRepository pipelineConfig.CiPipelineRepository
91+
appListingRepository repository.AppListingRepository
92+
cdPipelineRepository pipelineConfig.PipelineRepository
93+
enforcerUtil rbac.EnforcerUtil
94+
resourceGroupService resourceGroup.ResourceGroupService
95+
envRepository repository2.EnvironmentRepository
96+
imageTaggingService imageTagging.ImageTaggingService
97+
customTagService CustomTagService
98+
appWorkflowRepository appWorkflow.AppWorkflowRepository
99+
config *types.CiConfig
100+
k8sCommonService k8sPkg.K8sCommonService
101+
workFlowStageStatusService workflowStatus.WorkFlowStageStatusService
102+
workflowStatusLatestService workflowStatusLatest.WorkflowStatusLatestService
102103
}
103104

104105
func NewCiHandlerImpl(Logger *zap.SugaredLogger, ciService CiService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, gitSensorClient gitSensor.Client, ciWorkflowRepository pipelineConfig.CiWorkflowRepository,
105106
ciArtifactRepository repository.CiArtifactRepository, userService user.UserService, eventClient client.EventClient, eventFactory client.EventFactory, ciPipelineRepository pipelineConfig.CiPipelineRepository,
106107
appListingRepository repository.AppListingRepository, cdPipelineRepository pipelineConfig.PipelineRepository, enforcerUtil rbac.EnforcerUtil, resourceGroupService resourceGroup.ResourceGroupService, envRepository repository2.EnvironmentRepository,
107108
imageTaggingService imageTagging.ImageTaggingService, k8sCommonService k8sPkg.K8sCommonService, appWorkflowRepository appWorkflow.AppWorkflowRepository, customTagService CustomTagService,
108109
workFlowStageStatusService workflowStatus.WorkFlowStageStatusService,
109-
workflowStatusLatestRepository pipelineConfig.WorkflowStatusLatestRepository,
110+
workflowStatusLatestService workflowStatusLatest.WorkflowStatusLatestService,
110111
) *CiHandlerImpl {
111112
cih := &CiHandlerImpl{
112-
Logger: Logger,
113-
ciService: ciService,
114-
ciPipelineMaterialRepository: ciPipelineMaterialRepository,
115-
gitSensorClient: gitSensorClient,
116-
ciWorkflowRepository: ciWorkflowRepository,
117-
ciArtifactRepository: ciArtifactRepository,
118-
userService: userService,
119-
eventClient: eventClient,
120-
eventFactory: eventFactory,
121-
ciPipelineRepository: ciPipelineRepository,
122-
appListingRepository: appListingRepository,
123-
cdPipelineRepository: cdPipelineRepository,
124-
enforcerUtil: enforcerUtil,
125-
resourceGroupService: resourceGroupService,
126-
envRepository: envRepository,
127-
imageTaggingService: imageTaggingService,
128-
customTagService: customTagService,
129-
appWorkflowRepository: appWorkflowRepository,
130-
k8sCommonService: k8sCommonService,
131-
workFlowStageStatusService: workFlowStageStatusService,
132-
workflowStatusLatestRepository: workflowStatusLatestRepository,
113+
Logger: Logger,
114+
ciService: ciService,
115+
ciPipelineMaterialRepository: ciPipelineMaterialRepository,
116+
gitSensorClient: gitSensorClient,
117+
ciWorkflowRepository: ciWorkflowRepository,
118+
ciArtifactRepository: ciArtifactRepository,
119+
userService: userService,
120+
eventClient: eventClient,
121+
eventFactory: eventFactory,
122+
ciPipelineRepository: ciPipelineRepository,
123+
appListingRepository: appListingRepository,
124+
cdPipelineRepository: cdPipelineRepository,
125+
enforcerUtil: enforcerUtil,
126+
resourceGroupService: resourceGroupService,
127+
envRepository: envRepository,
128+
imageTaggingService: imageTaggingService,
129+
customTagService: customTagService,
130+
appWorkflowRepository: appWorkflowRepository,
131+
k8sCommonService: k8sCommonService,
132+
workFlowStageStatusService: workFlowStageStatusService,
133+
workflowStatusLatestService: workflowStatusLatestService,
133134
}
134135
config, err := types.GetCiConfig()
135136
if err != nil {
@@ -659,7 +660,7 @@ func (impl *CiHandlerImpl) FetchCiStatusForTriggerViewV1(appId int) ([]*pipeline
659660
return []*pipelineConfig.CiWorkflowStatus{}, nil
660661
}
661662

662-
latestStatusEntries, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineIds(allPipelineIds)
663+
latestStatusEntries, err := impl.workflowStatusLatestService.GetCiWorkflowStatusLatestByPipelineIds(allPipelineIds)
663664
if err != nil {
664665
impl.Logger.Errorw("error in checking latest status table, falling back to old method", "appId", appId, "err", err)
665666
return impl.ciWorkflowRepository.FIndCiWorkflowStatusesByAppId(appId)
@@ -747,7 +748,7 @@ func (impl *CiHandlerImpl) fetchLastTriggeredWorkflowsHybrid(pipelineIds []int)
747748
return []*pipelineConfig.CiWorkflow{}, nil
748749
}
749750

750-
latestStatusEntries, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineIds(pipelineIds)
751+
latestStatusEntries, err := impl.workflowStatusLatestService.GetCiWorkflowStatusLatestByPipelineIds(pipelineIds)
751752
if err != nil {
752753
impl.Logger.Errorw("error in checking latest status table, falling back to complex query", "pipelineIds", pipelineIds, "err", err)
753754
return impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(pipelineIds)

pkg/workflow/workflowStatusLatest/WorkflowStatusLatestService.go

Lines changed: 3 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import (
2020
"fmt"
2121
"time"
2222

23-
util2 "github.com/devtron-labs/devtron/internal/util"
24-
25-
"github.com/devtron-labs/devtron/api/bean"
2623
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
2724
"github.com/go-pg/pg"
2825
"go.uber.org/zap"
@@ -31,14 +28,10 @@ import (
3128
type WorkflowStatusLatestService interface {
3229
// CI Workflow Status Latest methods
3330
SaveCiWorkflowStatusLatest(tx *pg.Tx, pipelineId, appId, ciWorkflowId int, userId int32) error
34-
GetCiWorkflowStatusLatestByPipelineId(pipelineId int) (*CiWorkflowStatusLatest, error)
35-
GetCiWorkflowStatusLatestByAppId(appId int) ([]*CiWorkflowStatusLatest, error)
31+
GetCiWorkflowStatusLatestByPipelineIds(pipelineIds []int) ([]*pipelineConfig.CiWorkflowStatusLatest, error)
3632

3733
// CD Workflow Status Latest methods
3834
SaveCdWorkflowStatusLatest(tx *pg.Tx, pipelineId, appId, environmentId, workflowRunnerId int, workflowType string, userId int32) error
39-
GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error)
40-
GetCdWorkflowStatusLatestByAppId(appId int) ([]*CdWorkflowStatusLatest, error)
41-
GetCdWorkflowStatusLatestByPipelineId(pipelineId int) ([]*CdWorkflowStatusLatest, error)
4235
GetCdWorkflowLatestByPipelineIds(pipelineIds []int) ([]*CdWorkflowStatusLatest, error)
4336
}
4437

@@ -104,58 +97,8 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveCiWorkflowStatusLatest(tx *pg.T
10497
return impl.workflowStatusLatestRepository.SaveCiWorkflowStatusLatest(tx, model)
10598
}
10699

107-
func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByPipelineId(pipelineId int) (*CiWorkflowStatusLatest, error) {
108-
model, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineId(pipelineId)
109-
if err != nil {
110-
if err == pg.ErrNoRows {
111-
// Fallback to old method
112-
return impl.getCiWorkflowStatusFromOldMethod(pipelineId)
113-
}
114-
impl.logger.Errorw("error in getting ci workflow status latest", "err", err, "pipelineId", pipelineId)
115-
return nil, err
116-
}
117-
118-
// Get status from ci_workflow table
119-
ciWorkflow, err := impl.ciWorkflowRepository.FindById(model.CiWorkflowId)
120-
if err != nil {
121-
impl.logger.Errorw("error in getting ci workflow", "err", err, "ciWorkflowId", model.CiWorkflowId)
122-
return nil, err
123-
}
124-
125-
return &CiWorkflowStatusLatest{
126-
PipelineId: model.PipelineId,
127-
AppId: model.AppId,
128-
CiWorkflowId: model.CiWorkflowId,
129-
Status: ciWorkflow.Status,
130-
}, nil
131-
}
132-
133-
func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByAppId(appId int) ([]*CiWorkflowStatusLatest, error) {
134-
models, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByAppId(appId)
135-
if err != nil {
136-
impl.logger.Errorw("error in getting ci workflow status latest by app id", "err", err, "appId", appId)
137-
return nil, err
138-
}
139-
140-
var result []*CiWorkflowStatusLatest
141-
for _, model := range models {
142-
// Get status from ci_workflow table
143-
ciWorkflow, err := impl.ciWorkflowRepository.FindById(model.CiWorkflowId)
144-
if err != nil {
145-
impl.logger.Errorw("error in getting ci workflow", "err", err, "ciWorkflowId", model.CiWorkflowId)
146-
continue // Skip this entry if we can't get the workflow
147-
}
148-
149-
result = append(result, &CiWorkflowStatusLatest{
150-
PipelineId: model.PipelineId,
151-
AppId: model.AppId,
152-
CiWorkflowId: model.CiWorkflowId,
153-
Status: ciWorkflow.Status,
154-
StorageConfigured: ciWorkflow.BlobStorageEnabled,
155-
})
156-
}
157-
158-
return result, nil
100+
func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByPipelineIds(pipelineIds []int) ([]*pipelineConfig.CiWorkflowStatusLatest, error) {
101+
return impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineIds(pipelineIds)
159102
}
160103

161104
// CD Workflow Status Latest methods implementation
@@ -183,158 +126,6 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveCdWorkflowStatusLatest(tx *pg.T
183126
return impl.workflowStatusLatestRepository.SaveCdWorkflowStatusLatest(tx, model)
184127
}
185128

186-
func (impl *WorkflowStatusLatestServiceImpl) GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error) {
187-
model, err := impl.workflowStatusLatestRepository.GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(nil, pipelineId, workflowType)
188-
if err != nil {
189-
if err == pg.ErrNoRows {
190-
// Fallback to old method
191-
return impl.getCdWorkflowStatusFromOldMethod(pipelineId, workflowType)
192-
}
193-
impl.logger.Errorw("error in getting cd workflow status latest", "err", err, "pipelineId", pipelineId, "workflowType", workflowType)
194-
return nil, err
195-
}
196-
197-
// Get status from cd_workflow_runner table
198-
cdWorkflowRunner, err := impl.cdWorkflowRepository.FindBasicWorkflowRunnerById(model.WorkflowRunnerId)
199-
if err != nil {
200-
impl.logger.Errorw("error in getting cd workflow runner", "err", err, "workflowRunnerId", model.WorkflowRunnerId)
201-
return nil, err
202-
}
203-
204-
return &CdWorkflowStatusLatest{
205-
PipelineId: model.PipelineId,
206-
AppId: model.AppId,
207-
EnvironmentId: model.EnvironmentId,
208-
WorkflowType: model.WorkflowType,
209-
WorkflowRunnerId: model.WorkflowRunnerId,
210-
Status: cdWorkflowRunner.Status,
211-
}, nil
212-
}
213-
214-
func (impl *WorkflowStatusLatestServiceImpl) GetCdWorkflowStatusLatestByAppId(appId int) ([]*CdWorkflowStatusLatest, error) {
215-
models, err := impl.workflowStatusLatestRepository.GetCdWorkflowStatusLatestByAppId(appId)
216-
if err != nil {
217-
impl.logger.Errorw("error in getting cd workflow status latest by app id", "err", err, "appId", appId)
218-
return nil, err
219-
}
220-
221-
var result []*CdWorkflowStatusLatest
222-
for _, model := range models {
223-
// Get status from cd_workflow_runner table
224-
cdWorkflowRunner, err := impl.cdWorkflowRepository.FindBasicWorkflowRunnerById(model.WorkflowRunnerId)
225-
if err != nil {
226-
impl.logger.Errorw("error in getting cd workflow runner", "err", err, "workflowRunnerId", model.WorkflowRunnerId)
227-
continue // Skip this entry if we can't get the workflow runner
228-
}
229-
230-
result = append(result, &CdWorkflowStatusLatest{
231-
PipelineId: model.PipelineId,
232-
AppId: model.AppId,
233-
EnvironmentId: model.EnvironmentId,
234-
WorkflowType: model.WorkflowType,
235-
WorkflowRunnerId: model.WorkflowRunnerId,
236-
Status: cdWorkflowRunner.Status,
237-
})
238-
}
239-
240-
return result, nil
241-
}
242-
243-
func (impl *WorkflowStatusLatestServiceImpl) GetCdWorkflowStatusLatestByPipelineId(pipelineId int) ([]*CdWorkflowStatusLatest, error) {
244-
models, err := impl.workflowStatusLatestRepository.GetCdWorkflowStatusLatestByPipelineId(pipelineId)
245-
if err != nil {
246-
impl.logger.Errorw("error in getting cd workflow status latest by pipeline id", "err", err, "pipelineId", pipelineId)
247-
return nil, err
248-
}
249-
250-
var result []*CdWorkflowStatusLatest
251-
for _, model := range models {
252-
// Get status from cd_workflow_runner table
253-
cdWorkflowRunner, err := impl.cdWorkflowRepository.FindBasicWorkflowRunnerById(model.WorkflowRunnerId)
254-
if err != nil {
255-
impl.logger.Errorw("error in getting cd workflow runner", "err", err, "workflowRunnerId", model.WorkflowRunnerId)
256-
continue // Skip this entry if we can't get the workflow runner
257-
}
258-
259-
result = append(result, &CdWorkflowStatusLatest{
260-
PipelineId: model.PipelineId,
261-
AppId: model.AppId,
262-
EnvironmentId: model.EnvironmentId,
263-
WorkflowType: model.WorkflowType,
264-
WorkflowRunnerId: model.WorkflowRunnerId,
265-
Status: cdWorkflowRunner.Status,
266-
})
267-
}
268-
269-
return result, nil
270-
}
271-
272-
// Fallback methods to old implementation when no entry found in latest status tables
273-
func (impl *WorkflowStatusLatestServiceImpl) getCiWorkflowStatusFromOldMethod(pipelineId int) (*CiWorkflowStatusLatest, error) {
274-
// Get the latest CI workflow for this pipeline using the old method
275-
workflow, err := impl.ciWorkflowRepository.FindLastTriggeredWorkflow(pipelineId)
276-
if err != nil {
277-
if util2.IsErrNoRows(err) {
278-
return &CiWorkflowStatusLatest{
279-
PipelineId: pipelineId,
280-
AppId: 0, // Will need to be populated from pipeline info
281-
CiWorkflowId: 0,
282-
Status: "Not Triggered",
283-
}, nil
284-
}
285-
impl.logger.Errorw("error in getting last triggered workflow", "err", err, "pipelineId", pipelineId)
286-
return nil, err
287-
}
288-
289-
return &CiWorkflowStatusLatest{
290-
PipelineId: pipelineId,
291-
AppId: workflow.CiPipeline.AppId,
292-
CiWorkflowId: workflow.Id,
293-
Status: workflow.Status,
294-
}, nil
295-
}
296-
297-
func (impl *WorkflowStatusLatestServiceImpl) getCdWorkflowStatusFromOldMethod(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error) {
298-
// Convert workflowType to the appropriate enum
299-
var runnerType bean.WorkflowType
300-
switch workflowType {
301-
case "PRE":
302-
runnerType = bean.CD_WORKFLOW_TYPE_PRE
303-
case "DEPLOY":
304-
runnerType = bean.CD_WORKFLOW_TYPE_DEPLOY
305-
case "POST":
306-
runnerType = bean.CD_WORKFLOW_TYPE_POST
307-
default:
308-
runnerType = bean.WorkflowType(workflowType)
309-
}
310-
311-
// Get the latest CD workflow runner for this pipeline and type using the old method
312-
wfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, runnerType)
313-
if err != nil {
314-
if err == pg.ErrNoRows {
315-
return &CdWorkflowStatusLatest{
316-
PipelineId: pipelineId,
317-
AppId: 0, // Will need to be populated from pipeline info
318-
EnvironmentId: 0,
319-
WorkflowType: workflowType,
320-
WorkflowRunnerId: 0,
321-
Status: "Not Triggered",
322-
}, nil
323-
}
324-
impl.logger.Errorw("error in getting latest cd workflow runner", "err", err, "pipelineId", pipelineId, "runnerType", runnerType)
325-
return nil, err
326-
}
327-
328-
return &CdWorkflowStatusLatest{
329-
PipelineId: pipelineId,
330-
AppId: wfr.CdWorkflow.Pipeline.AppId,
331-
EnvironmentId: wfr.CdWorkflow.Pipeline.EnvironmentId,
332-
WorkflowType: workflowType,
333-
WorkflowRunnerId: wfr.Id,
334-
Status: wfr.Status,
335-
}, nil
336-
}
337-
338129
func (impl *WorkflowStatusLatestServiceImpl) GetCdWorkflowLatestByPipelineIds(pipelineIds []int) ([]*CdWorkflowStatusLatest, error) {
339130
cdWorkflowStatusLatest, err := impl.workflowStatusLatestRepository.GetCdWorkflowStatusLatestByPipelineIds(pipelineIds)
340131
if err != nil {

0 commit comments

Comments
 (0)