@@ -146,6 +146,7 @@ type PipelineRepository interface {
146
146
GetAllAppsByClusterAndDeploymentAppType (clusterIds []int , deploymentAppName string ) ([]* PipelineDeploymentConfigObj , error )
147
147
GetAllArgoAppInfoByDeploymentAppNames (deploymentAppNames []string ) ([]* PipelineDeploymentConfigObj , error )
148
148
FindEnvIdsByIdsInIncludingDeleted (ids []int ) ([]int , error )
149
+ GetPipelineCountByDeploymentType (deploymentType string ) (int , error )
149
150
}
150
151
151
152
type CiArtifactDTO struct {
@@ -672,14 +673,14 @@ func (impl *PipelineRepositoryImpl) GetAppAndEnvDetailsForDeploymentAppTypePipel
672
673
673
674
func (impl * PipelineRepositoryImpl ) GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines (pendingSinceSeconds int , timeForDegradation int ) ([]* Pipeline , error ) {
674
675
var pipelines []* Pipeline
675
- queryString := `select p.* from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
676
- inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
676
+ queryString := `select p.* from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
677
+ inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
677
678
left join deployment_config dc on dc.active=true and dc.app_id = p.app_id and dc.environment_id=p.environment_id
678
- where cwr.id in (select cd_workflow_runner_id from pipeline_status_timeline
679
- where id in
680
- (select DISTINCT ON (cd_workflow_runner_id) max(id) as id from pipeline_status_timeline
681
- group by cd_workflow_runner_id, id order by cd_workflow_runner_id,id desc)
682
- and status in (?) and status_time < NOW() - INTERVAL '? seconds')
679
+ where cwr.id in (select cd_workflow_runner_id from pipeline_status_timeline
680
+ where id in
681
+ (select DISTINCT ON (cd_workflow_runner_id) max(id) as id from pipeline_status_timeline
682
+ group by cd_workflow_runner_id, id order by cd_workflow_runner_id,id desc)
683
+ and status in (?) and status_time < NOW() - INTERVAL '? seconds')
683
684
and cwr.started_on > NOW() - INTERVAL '? minutes' and (p.deployment_app_type=? or dc.deployment_app_type=?) and p.deleted=?;`
684
685
_ , err := impl .dbConnection .Query (& pipelines , queryString ,
685
686
pg .In ([]timelineStatus.TimelineStatus {timelineStatus .TIMELINE_STATUS_KUBECTL_APPLY_SYNCED ,
@@ -694,11 +695,11 @@ func (impl *PipelineRepositoryImpl) GetArgoPipelinesHavingTriggersStuckInLastPos
694
695
695
696
func (impl * PipelineRepositoryImpl ) GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses (getPipelineDeployedBeforeMinutes int , getPipelineDeployedWithinHours int ) ([]* Pipeline , error ) {
696
697
var pipelines []* Pipeline
697
- queryString := `select p.id from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
698
- inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
698
+ queryString := `select p.id from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
699
+ inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
699
700
left join deployment_config dc on dc.active=true and dc.app_id = p.app_id and dc.environment_id=p.environment_id
700
- where cwr.id in (select id from cd_workflow_runner
701
- where started_on < NOW() - INTERVAL '? minutes' and started_on > NOW() - INTERVAL '? hours' and status not in (?)
701
+ where cwr.id in (select id from cd_workflow_runner
702
+ where started_on < NOW() - INTERVAL '? minutes' and started_on > NOW() - INTERVAL '? hours' and status not in (?)
702
703
and workflow_type=? and cd_workflow_id in (select DISTINCT ON (pipeline_id) max(id) as id from cd_workflow
703
704
group by pipeline_id, id order by pipeline_id, id desc))
704
705
and (p.deployment_app_type=? or dc.deployment_app_type=?) and p.deleted=?;`
@@ -967,3 +968,24 @@ func (impl *PipelineRepositoryImpl) FindEnvIdsByIdsInIncludingDeleted(ids []int)
967
968
}
968
969
return envIds , err
969
970
}
971
+
972
+ func (impl * PipelineRepositoryImpl ) GetPipelineCountByDeploymentType (deploymentType string ) (int , error ) {
973
+ var count int
974
+ // Count pipelines by deployment type, considering both pipeline table and deployment_config table
975
+ // The deployment_config table can override the deployment type from the pipeline table
976
+ query := `
977
+ SELECT COUNT(DISTINCT p.id)
978
+ FROM pipeline p
979
+ LEFT JOIN deployment_config dc ON dc.active = true
980
+ AND dc.app_id = p.app_id
981
+ AND dc.environment_id = p.environment_id
982
+ WHERE p.deleted = false
983
+ AND (p.deployment_app_type = ? OR dc.deployment_app_type = ?)
984
+ `
985
+ _ , err := impl .dbConnection .Query (& count , query , deploymentType , deploymentType )
986
+ if err != nil {
987
+ impl .logger .Errorw ("error getting pipeline count by deployment type" , "deploymentType" , deploymentType , "err" , err )
988
+ return 0 , err
989
+ }
990
+ return count , nil
991
+ }
0 commit comments