@@ -64,7 +64,7 @@ func (impl *CdWorkflowRunnerReadServiceImpl) GetWfrStatusForLatestRunners(pipeli
64
64
return nil , err
65
65
}
66
66
67
- var pipelineIdToCiPipelineIdMap map [int ]int
67
+ pipelineIdToCiPipelineIdMap := make ( map [int ]int )
68
68
for _ , item := range pipelines {
69
69
pipelineIdToCiPipelineIdMap [item .Id ] = item .CiPipelineId
70
70
}
@@ -78,51 +78,66 @@ func (impl *CdWorkflowRunnerReadServiceImpl) GetWfrStatusForLatestRunners(pipeli
78
78
})
79
79
}
80
80
81
- var cdWorfklowLatestMap map [int ]map [ bean2.WorkflowType ] bool
81
+ cdWorfklowLatestMap := make ( map [int ][] bean2.WorkflowType )
82
82
for _ , item := range cdWorkflowLatest {
83
83
if _ , ok := cdWorfklowLatestMap [item .PipelineId ]; ! ok {
84
- cdWorfklowLatestMap [item .PipelineId ] = make (map [ bean2.WorkflowType ] bool )
84
+ cdWorfklowLatestMap [item .PipelineId ] = make ([] bean2.WorkflowType , 0 )
85
85
}
86
- cdWorfklowLatestMap [item .PipelineId ][ bean2 .WorkflowType (item .WorkflowType )] = true
86
+ cdWorfklowLatestMap [item .PipelineId ] = append ( cdWorfklowLatestMap [ item . PipelineId ], bean2 .WorkflowType (item .WorkflowType ))
87
87
}
88
88
89
89
pipelineStage , err := impl .pipelineStageRepository .GetAllCdStagesByCdPipelineIds (pipelineIds )
90
90
if err != nil {
91
91
impl .logger .Errorw ("error in fetching pipeline stages" , "pipelineId" , pipelineIds , "err" , err )
92
92
return nil , err
93
93
}
94
- pipelineStageMap := make (map [int ]map [ bean2.WorkflowType ] bool )
94
+ pipelineStageMap := make (map [int ][] bean2.WorkflowType )
95
95
for _ , item := range pipelineStage {
96
96
if _ , ok := pipelineStageMap [item .CdPipelineId ]; ! ok {
97
- pipelineStageMap [item .CdPipelineId ] = make (map [ bean2.WorkflowType ] bool )
97
+ pipelineStageMap [item .CdPipelineId ] = make ([] bean2.WorkflowType , 0 )
98
98
}
99
99
if item .Type == repository2 .PIPELINE_STAGE_TYPE_PRE_CD {
100
- pipelineStageMap [item.CdPipelineId ][bean2. CD_WORKFLOW_TYPE_PRE ] = true
100
+ pipelineStageMap [item .CdPipelineId ] = append ( pipelineStageMap [ item . CdPipelineId ], bean2 . CD_WORKFLOW_TYPE_PRE )
101
101
} else if item .Type == repository2 .PIPELINE_STAGE_TYPE_POST_CD {
102
- pipelineStageMap [item.CdPipelineId ][bean2. CD_WORKFLOW_TYPE_POST ] = true
102
+ pipelineStageMap [item .CdPipelineId ] = append ( pipelineStageMap [ item . CdPipelineId ], bean2 . CD_WORKFLOW_TYPE_POST )
103
103
}
104
104
}
105
105
106
106
// calculating all the pipelines not present in the index table cdWorkflowLatest
107
- var pipelinesAbsentInCache map [int ]bean2.WorkflowType
107
+ pipelinesAbsentInCache := make ( map [int ][] bean2.WorkflowType )
108
108
for _ , item := range pipelines {
109
- if _ , ok := cdWorfklowLatestMap [item .Id ]; ! ok {
110
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_PRE
111
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_DEPLOY
112
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_POST
109
+ if stages , ok := cdWorfklowLatestMap [item .Id ]; ! ok || len (stages ) == 0 {
110
+ pipelinesAbsentInCache [item .Id ] = append (pipelinesAbsentInCache [item .Id ], bean2 .CD_WORKFLOW_TYPE_PRE , bean2 .CD_WORKFLOW_TYPE_POST , bean2 .CD_WORKFLOW_TYPE_DEPLOY )
113
111
} else {
114
- if _ , ok := pipelineStageMap [item.Id ][bean2.CD_WORKFLOW_TYPE_PRE ]; ok {
115
- if val , ok := cdWorfklowLatestMap [item.Id ][bean2.CD_WORKFLOW_TYPE_PRE ]; ! ok || ! val {
116
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_PRE
112
+ isPreCDStageAbsent , isPostCdStageAbsent , isDeployStageAbsent := true , true , true
113
+ for _ , stage := range stages {
114
+ switch stage {
115
+ case bean2 .CD_WORKFLOW_TYPE_PRE :
116
+ isPreCDStageAbsent = false
117
+ case bean2 .CD_WORKFLOW_TYPE_POST :
118
+ isPostCdStageAbsent = false
119
+ case bean2 .CD_WORKFLOW_TYPE_DEPLOY :
120
+ isDeployStageAbsent = false
117
121
}
118
122
}
119
- if _ , ok := pipelineStageMap [item.Id ][bean2.CD_WORKFLOW_TYPE_POST ]; ok {
120
- if val , ok := cdWorfklowLatestMap [item.Id ][bean2.CD_WORKFLOW_TYPE_POST ]; ! ok || ! val {
121
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_POST
122
- }
123
+ if isDeployStageAbsent {
124
+ pipelinesAbsentInCache [item .Id ] = append (pipelinesAbsentInCache [item .Id ], bean2 .CD_WORKFLOW_TYPE_DEPLOY )
123
125
}
124
- if val , ok := cdWorfklowLatestMap [item.Id ][bean2.CD_WORKFLOW_TYPE_DEPLOY ]; ! ok || ! val {
125
- pipelinesAbsentInCache [item .Id ] = bean2 .CD_WORKFLOW_TYPE_POST
126
+ if configuredStages , ok := pipelineStageMap [item .Id ]; ok {
127
+ var isPreCDConfigured , isPostCDConfigured bool
128
+ for _ , stage := range configuredStages {
129
+ if stage == bean2 .CD_WORKFLOW_TYPE_PRE {
130
+ isPreCDConfigured = true
131
+ } else if stage == bean2 .CD_WORKFLOW_TYPE_POST {
132
+ isPostCDConfigured = true
133
+ }
134
+ }
135
+ if isPreCDConfigured && isPreCDStageAbsent {
136
+ pipelinesAbsentInCache [item .Id ] = append (pipelinesAbsentInCache [item .Id ], bean2 .CD_WORKFLOW_TYPE_PRE )
137
+ }
138
+ if isPostCDConfigured && isPostCdStageAbsent {
139
+ pipelinesAbsentInCache [item .Id ] = append (pipelinesAbsentInCache [item .Id ], bean2 .CD_WORKFLOW_TYPE_POST )
140
+ }
126
141
}
127
142
}
128
143
}
0 commit comments