Skip to content

Commit 20dc988

Browse files
committed
dev testing fixes
1 parent 1368559 commit 20dc988

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type CdWorkflowRepository interface {
7171
IsLatestWf(pipelineId int, wfId int) (bool, error)
7272
FindLatestCdWorkflowByPipelineId(pipelineIds []int) (*CdWorkflow, error)
7373
FindLatestCdWorkflowByPipelineIdV2(pipelineIds []int) ([]*CdWorkflow, error)
74-
FetchAllCdStagesLatestEntity(pipelineWorkflowPairs map[int]apiBean.WorkflowType) ([]*CdWorkflowStatus, error)
74+
FetchAllCdStagesLatestEntity(pipelineWorkflowPairs map[int][]apiBean.WorkflowType) ([]*CdWorkflowStatus, error)
7575
FetchAllCdStagesLatestEntityStatus(wfrIds []int) ([]*CdWorkflowRunner, error)
7676
ExistsByStatus(status string) (bool, error)
7777
FetchEnvAllCdStagesLatestEntityStatus(wfrIds []int, envID int) ([]*CdWorkflowRunner, error)
@@ -580,7 +580,7 @@ func (impl *CdWorkflowRepositoryImpl) IsLatestWf(pipelineId int, wfId int) (bool
580580
return !exists, err
581581
}
582582

583-
func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntity(pipelineWorkflowPairs map[int]apiBean.WorkflowType) ([]*CdWorkflowStatus, error) {
583+
func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntity(pipelineWorkflowPairs map[int][]apiBean.WorkflowType) ([]*CdWorkflowStatus, error) {
584584
var cdWorkflowStatus []*CdWorkflowStatus
585585
if len(pipelineWorkflowPairs) == 0 {
586586
return cdWorkflowStatus, nil
@@ -598,14 +598,15 @@ func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntity(pipelineWorkf
598598
return cdWorkflowStatus, nil
599599
}
600600

601-
func buildPipelineTypeValuesList(pairs map[int]apiBean.WorkflowType) string {
601+
func buildPipelineTypeValuesList(pairs map[int][]apiBean.WorkflowType) string {
602602
var values []string
603-
for pipelineId, workflowType := range pairs {
604-
values = append(values, fmt.Sprintf("(%d,'%s')", pipelineId, workflowType))
603+
for pipelineId, workflowTypes := range pairs {
604+
for _, workflowType := range workflowTypes {
605+
values = append(values, fmt.Sprintf("(%d,'%s')", pipelineId, workflowType))
606+
}
605607
}
606608
return strings.Join(values, ",")
607609
}
608-
609610
func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntityStatus(wfrIds []int) ([]*CdWorkflowRunner, error) {
610611
var wfrList []*CdWorkflowRunner
611612
err := impl.dbConnection.Model(&wfrList).

pkg/workflow/cd/read/CdWorkflowRunnerReadService.go

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (impl *CdWorkflowRunnerReadServiceImpl) GetWfrStatusForLatestRunners(pipeli
6464
return nil, err
6565
}
6666

67-
var pipelineIdToCiPipelineIdMap map[int]int
67+
pipelineIdToCiPipelineIdMap := make(map[int]int)
6868
for _, item := range pipelines {
6969
pipelineIdToCiPipelineIdMap[item.Id] = item.CiPipelineId
7070
}
@@ -78,51 +78,66 @@ func (impl *CdWorkflowRunnerReadServiceImpl) GetWfrStatusForLatestRunners(pipeli
7878
})
7979
}
8080

81-
var cdWorfklowLatestMap map[int]map[bean2.WorkflowType]bool
81+
cdWorfklowLatestMap := make(map[int][]bean2.WorkflowType)
8282
for _, item := range cdWorkflowLatest {
8383
if _, ok := cdWorfklowLatestMap[item.PipelineId]; !ok {
84-
cdWorfklowLatestMap[item.PipelineId] = make(map[bean2.WorkflowType]bool)
84+
cdWorfklowLatestMap[item.PipelineId] = make([]bean2.WorkflowType, 0)
8585
}
86-
cdWorfklowLatestMap[item.PipelineId][bean2.WorkflowType(item.WorkflowType)] = true
86+
cdWorfklowLatestMap[item.PipelineId] = append(cdWorfklowLatestMap[item.PipelineId], bean2.WorkflowType(item.WorkflowType))
8787
}
8888

8989
pipelineStage, err := impl.pipelineStageRepository.GetAllCdStagesByCdPipelineIds(pipelineIds)
9090
if err != nil {
9191
impl.logger.Errorw("error in fetching pipeline stages", "pipelineId", pipelineIds, "err", err)
9292
return nil, err
9393
}
94-
pipelineStageMap := make(map[int]map[bean2.WorkflowType]bool)
94+
pipelineStageMap := make(map[int][]bean2.WorkflowType)
9595
for _, item := range pipelineStage {
9696
if _, ok := pipelineStageMap[item.CdPipelineId]; !ok {
97-
pipelineStageMap[item.CdPipelineId] = make(map[bean2.WorkflowType]bool)
97+
pipelineStageMap[item.CdPipelineId] = make([]bean2.WorkflowType, 0)
9898
}
9999
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)
101101
} 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)
103103
}
104104
}
105105

106106
// 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)
108108
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)
113111
} 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
117121
}
118122
}
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)
123125
}
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+
}
126141
}
127142
}
128143
}

0 commit comments

Comments
 (0)