@@ -32,6 +32,7 @@ import (
32
32
"github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus"
33
33
bean5 "github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus/bean"
34
34
"github.com/devtron-labs/devtron/pkg/workflow/cd"
35
+ "github.com/devtron-labs/devtron/pkg/workflow/cd/read"
35
36
"github.com/devtron-labs/devtron/pkg/workflow/workflowStatusLatest"
36
37
"slices"
37
38
"strconv"
@@ -93,6 +94,7 @@ type CdHandlerImpl struct {
93
94
cdWorkflowRunnerService cd.CdWorkflowRunnerService
94
95
WorkflowStatusLatestService workflowStatusLatest.WorkflowStatusLatestService
95
96
pipelineStageRepository repository2.PipelineStageRepository
97
+ cdWorkflowRunnerReadService read.CdWorkflowRunnerReadService
96
98
}
97
99
98
100
func NewCdHandlerImpl (Logger * zap.SugaredLogger , userService user.UserService ,
@@ -109,6 +111,7 @@ func NewCdHandlerImpl(Logger *zap.SugaredLogger, userService user.UserService,
109
111
cdWorkflowRunnerService cd.CdWorkflowRunnerService ,
110
112
WorkflowStatusLatestService workflowStatusLatest.WorkflowStatusLatestService ,
111
113
pipelineStageRepository repository2.PipelineStageRepository ,
114
+ cdWorkflowRunnerReadService read.CdWorkflowRunnerReadService ,
112
115
) * CdHandlerImpl {
113
116
cdh := & CdHandlerImpl {
114
117
Logger : Logger ,
@@ -129,6 +132,7 @@ func NewCdHandlerImpl(Logger *zap.SugaredLogger, userService user.UserService,
129
132
cdWorkflowRunnerService : cdWorkflowRunnerService ,
130
133
WorkflowStatusLatestService : WorkflowStatusLatestService ,
131
134
pipelineStageRepository : pipelineStageRepository ,
135
+ cdWorkflowRunnerReadService : cdWorkflowRunnerReadService ,
132
136
}
133
137
config , err := types .GetCdConfig ()
134
138
if err != nil {
@@ -602,7 +606,7 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerView(appId int) ([]*p
602
606
return cdWorkflowStatus , nil
603
607
}
604
608
605
- result , err := impl .getWfrStatusForLatestRunners (pipelineIds , pipelines )
609
+ result , err := impl .cdWorkflowRunnerReadService . GetWfrStatusForLatestRunners (pipelineIds , pipelines )
606
610
if err != nil {
607
611
impl .Logger .Errorw ("error in fetching wfrIds" , "pipelineIds" , pipelineIds , "err" , err )
608
612
return cdWorkflowStatus , err
@@ -692,88 +696,6 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerView(appId int) ([]*p
692
696
return cdWorkflowStatus , err
693
697
}
694
698
695
- func (impl * CdHandlerImpl ) getWfrStatusForLatestRunners (pipelineIds []int , pipelines []* pipelineConfig.Pipeline ) ([]* pipelineConfig.CdWorkflowStatus , error ) {
696
- // fetching the latest pipeline from the index table - cdWorkflowLatest
697
- var result []* pipelineConfig.CdWorkflowStatus
698
- cdWorkflowLatest , err := impl .WorkflowStatusLatestService .GetCdWorkflowLatestByPipelineIds (pipelineIds )
699
- if err != nil {
700
- impl .Logger .Errorw ("error in getting latest by pipelineId" , "pipelineId" , pipelineIds , "err" , err )
701
- return nil , err
702
- }
703
-
704
- var pipelineIdToCiPipelineIdMap map [int ]int
705
- for _ , item := range pipelines {
706
- pipelineIdToCiPipelineIdMap [item .Id ] = item .CiPipelineId
707
- }
708
-
709
- for _ , item := range cdWorkflowLatest {
710
- result = append (result , & pipelineConfig.CdWorkflowStatus {
711
- CiPipelineId : pipelineIdToCiPipelineIdMap [item .PipelineId ],
712
- PipelineId : item .PipelineId ,
713
- WorkflowType : item .WorkflowType ,
714
- WfrId : item .WorkflowRunnerId ,
715
- })
716
- }
717
-
718
- var cdWorfklowLatestMap map [int ]map [bean.WorkflowType ]bool
719
- for _ , item := range cdWorkflowLatest {
720
- if _ , ok := cdWorfklowLatestMap [item .PipelineId ]; ! ok {
721
- cdWorfklowLatestMap [item .PipelineId ] = make (map [bean.WorkflowType ]bool )
722
- }
723
- cdWorfklowLatestMap [item .PipelineId ][bean .WorkflowType (item .WorkflowType )] = true
724
- }
725
-
726
- pipelineStage , err := impl .pipelineStageRepository .GetAllCdStagesByCdPipelineIds (pipelineIds )
727
- if err != nil {
728
- impl .Logger .Errorw ("error in fetching pipeline stages" , "pipelineId" , pipelineIds , "err" , err )
729
- return nil , err
730
- }
731
- pipelineStageMap := make (map [int ]map [bean.WorkflowType ]bool )
732
- for _ , item := range pipelineStage {
733
- if _ , ok := pipelineStageMap [item .CdPipelineId ]; ! ok {
734
- pipelineStageMap [item .CdPipelineId ] = make (map [bean.WorkflowType ]bool )
735
- }
736
- if item .Type == repository2 .PIPELINE_STAGE_TYPE_PRE_CD {
737
- pipelineStageMap [item.CdPipelineId ][bean.CD_WORKFLOW_TYPE_PRE ] = true
738
- } else if item .Type == repository2 .PIPELINE_STAGE_TYPE_POST_CD {
739
- pipelineStageMap [item.CdPipelineId ][bean.CD_WORKFLOW_TYPE_POST ] = true
740
- }
741
- }
742
-
743
- // calculating all the pipelines not present in the index table cdWorkflowLatest
744
- var pipelinesAbsentInCache map [int ]bean.WorkflowType
745
- for _ , item := range pipelines {
746
- if _ , ok := cdWorfklowLatestMap [item .Id ]; ! ok {
747
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_PRE
748
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_DEPLOY
749
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_POST
750
- } else {
751
- if _ , ok := pipelineStageMap [item.Id ][bean.CD_WORKFLOW_TYPE_PRE ]; ok {
752
- if val , ok := cdWorfklowLatestMap [item.Id ][bean.CD_WORKFLOW_TYPE_PRE ]; ! ok || ! val {
753
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_PRE
754
- }
755
- }
756
- if _ , ok := pipelineStageMap [item.Id ][bean.CD_WORKFLOW_TYPE_POST ]; ok {
757
- if val , ok := cdWorfklowLatestMap [item.Id ][bean.CD_WORKFLOW_TYPE_POST ]; ! ok || ! val {
758
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_POST
759
- }
760
- }
761
- if val , ok := cdWorfklowLatestMap [item.Id ][bean.CD_WORKFLOW_TYPE_DEPLOY ]; ! ok || ! val {
762
- pipelinesAbsentInCache [item .Id ] = bean .CD_WORKFLOW_TYPE_POST
763
- }
764
- }
765
- }
766
- if len (pipelinesAbsentInCache ) > 0 {
767
- remainingRunners , err := impl .cdWorkflowRepository .FetchAllCdStagesLatestEntity (pipelinesAbsentInCache )
768
- if err != nil {
769
- impl .Logger .Errorw ("error in fetching all cd stages latest entity" , "pipelinesAbsentInCache" , pipelinesAbsentInCache , "err" , err )
770
- return nil , err
771
- }
772
- result = append (result , remainingRunners ... )
773
- }
774
- return result , nil
775
- }
776
-
777
699
func (impl * CdHandlerImpl ) FetchAppWorkflowStatusForTriggerViewForEnvironment (request resourceGroup2.ResourceGroupingRequest , token string ) ([]* pipelineConfig.CdWorkflowStatus , error ) {
778
700
cdWorkflowStatus := make ([]* pipelineConfig.CdWorkflowStatus , 0 )
779
701
var pipelines []* pipelineConfig.Pipeline
@@ -848,7 +770,7 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerViewForEnvironment(re
848
770
849
771
cdMap := make (map [int ]* pipelineConfig.CdWorkflowStatus )
850
772
851
- wfrStatus , err := impl .getWfrStatusForLatestRunners (pipelineIds , pipelines )
773
+ wfrStatus , err := impl .cdWorkflowRunnerReadService . GetWfrStatusForLatestRunners (pipelineIds , pipelines )
852
774
if err != nil {
853
775
impl .Logger .Errorw ("error in fetching wfrIds" , "pipelineIds" , pipelineIds , "err" , err )
854
776
return cdWorkflowStatus , err
@@ -1000,7 +922,7 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou
1000
922
return deploymentStatuses , nil
1001
923
}
1002
924
_ , span = otel .Tracer ("orchestrator" ).Start (request .Ctx , "pipelineBuilder.FetchAllCdStagesLatestEntity" )
1003
- result , err := impl .getWfrStatusForLatestRunners (pipelineIds , cdPipelines )
925
+ result , err := impl .cdWorkflowRunnerReadService . GetWfrStatusForLatestRunners (pipelineIds , cdPipelines )
1004
926
span .End ()
1005
927
if err != nil {
1006
928
return deploymentStatuses , err
0 commit comments