Skip to content

Commit 66e137a

Browse files
authored
Merge pull request #55 from devtron-labs/oss-sync-15mar-2
Oss sync
2 parents acf5121 + 3336862 commit 66e137a

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

client/cron/CdApplicationStatusUpdateHandler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ func (impl *CdApplicationStatusUpdateHandlerImpl) HelmApplicationStatusUpdate()
134134
}
135135

136136
func (impl *CdApplicationStatusUpdateHandlerImpl) ArgoApplicationStatusUpdate() {
137-
degradedTime, err := strconv.Atoi(impl.AppStatusConfig.PipelineDegradedTime)
137+
getPipelineDeployedBeforeMinutes, err := strconv.Atoi(impl.AppStatusConfig.PipelineDegradedTime)
138138
if err != nil {
139139
impl.logger.Errorw("error in converting string to int", "err", err)
140140
return
141141
}
142-
143-
err = impl.CdHandler.CheckArgoAppStatusPeriodicallyAndUpdateInDb(degradedTime)
142+
getPipelineDeployedWithinHours := impl.AppStatusConfig.GetPipelineDeployedWithinHours
143+
err = impl.CdHandler.CheckArgoAppStatusPeriodicallyAndUpdateInDb(getPipelineDeployedBeforeMinutes, getPipelineDeployedWithinHours)
144144
if err != nil {
145145
impl.logger.Errorw("error argo app status update - cron job", "err", err)
146146
return

internal/sql/repository/pipelineConfig/PipelineRepository.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type PipelineRepository interface {
9797
FindNumberOfAppsWithCdPipeline(appIds []int) (count int, err error)
9898
GetAppAndEnvDetailsForDeploymentAppTypePipeline(deploymentAppType string, clusterIds []int) ([]*Pipeline, error)
9999
GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines(pendingSinceSeconds int, timeForDegradation int) ([]*Pipeline, error)
100-
GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(deployedBeforeMinutes int) ([]*Pipeline, error)
100+
GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(deployedBeforeMinutes int, getPipelineDeployedWithinHours int) ([]*Pipeline, error)
101101
FindIdsByAppIdsAndEnvironmentIds(appIds, environmentIds []int) (ids []int, err error)
102102
FindIdsByProjectIdsAndEnvironmentIds(projectIds, environmentIds []int) ([]int, error)
103103

@@ -524,16 +524,16 @@ func (impl PipelineRepositoryImpl) GetArgoPipelinesHavingTriggersStuckInLastPoss
524524
return pipelines, nil
525525
}
526526

527-
func (impl PipelineRepositoryImpl) GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(deployedBeforeMinutes int) ([]*Pipeline, error) {
527+
func (impl PipelineRepositoryImpl) GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(getPipelineDeployedBeforeMinutes int, getPipelineDeployedWithinHours int) ([]*Pipeline, error) {
528528
var pipelines []*Pipeline
529529
queryString := `select p.* from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
530530
inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
531531
where cwr.id in (select id from cd_workflow_runner
532-
where started_on < NOW() - INTERVAL '? minutes' and status not in (?)
532+
where started_on < NOW() - INTERVAL '? minutes' and started_on > NOW() - INTERVAL '? hours' and status not in (?)
533533
and workflow_type=? and cd_workflow_id in (select DISTINCT ON (pipeline_id) max(id) as id from cd_workflow
534534
group by pipeline_id, id order by pipeline_id, id desc))
535535
and p.deployment_app_type=? and p.deleted=?;`
536-
_, err := impl.dbConnection.Query(&pipelines, queryString, deployedBeforeMinutes,
536+
_, err := impl.dbConnection.Query(&pipelines, queryString, getPipelineDeployedBeforeMinutes, getPipelineDeployedWithinHours,
537537
pg.In([]string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded)}),
538538
bean.CD_WORKFLOW_TYPE_DEPLOY, util.PIPELINE_DEPLOYMENT_TYPE_ACD, false)
539539
if err != nil {

internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/app/AppService.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ import (
8787
type AppServiceConfig struct {
8888
CdPipelineStatusCronTime string `env:"CD_PIPELINE_STATUS_CRON_TIME" envDefault:"*/2 * * * *"`
8989
CdHelmPipelineStatusCronTime string `env:"CD_HELM_PIPELINE_STATUS_CRON_TIME" envDefault:"*/2 * * * *"`
90-
CdPipelineStatusTimeoutDuration string `env:"CD_PIPELINE_STATUS_TIMEOUT_DURATION" envDefault:"20"` //in minutes
91-
PipelineDegradedTime string `env:"PIPELINE_DEGRADED_TIME" envDefault:"10"` //in minutes
92-
HelmPipelineStatusCheckEligibleTime string `env:"HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME" envDefault:"120"` //in seconds
90+
CdPipelineStatusTimeoutDuration string `env:"CD_PIPELINE_STATUS_TIMEOUT_DURATION" envDefault:"20"` //in minutes
91+
PipelineDegradedTime string `env:"PIPELINE_DEGRADED_TIME" envDefault:"10"` //in minutes
92+
GetPipelineDeployedWithinHours int `env:"DEPLOY_STATUS_CRON_GET_PIPELINE_DEPLOYED_WITHIN_HOURS" envDefault:"12"` //in hours
93+
HelmPipelineStatusCheckEligibleTime string `env:"HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME" envDefault:"120"` //in seconds
9394
ExposeCDMetrics bool `env:"EXPOSE_CD_METRICS" envDefault:"false"`
9495
}
9596

pkg/pipeline/CdHandler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type CdHandler interface {
6161
CancelStage(workflowRunnerId int, userId int32) (int, error)
6262
FetchAppWorkflowStatusForTriggerView(appId int) ([]*pipelineConfig.CdWorkflowStatus, error)
6363
CheckHelmAppStatusPeriodicallyAndUpdateInDb(helmPipelineStatusCheckEligibleTime int) error
64-
CheckArgoAppStatusPeriodicallyAndUpdateInDb(timeForDegradation int) error
64+
CheckArgoAppStatusPeriodicallyAndUpdateInDb(getPipelineDeployedBeforeMinutes int, getPipelineDeployedWithinHours int) error
6565
CheckArgoPipelineTimelineStatusPeriodicallyAndUpdateInDb(pendingSinceSeconds int, timeForDegradation int) error
6666
UpdatePipelineTimelineAndStatusByLiveApplicationFetch(pipeline *pipelineConfig.Pipeline, userId int32) (err error, isTimelineUpdated bool)
6767
CheckAndSendArgoPipelineStatusSyncEventIfNeeded(pipelineId int, userId int32)
@@ -164,8 +164,8 @@ const WorklowTypeDeploy = "DEPLOY"
164164
const WorklowTypePre = "PRE"
165165
const WorklowTypePost = "POST"
166166

167-
func (impl *CdHandlerImpl) CheckArgoAppStatusPeriodicallyAndUpdateInDb(deployedBeforeMinutes int) error {
168-
pipelines, err := impl.pipelineRepository.GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(deployedBeforeMinutes)
167+
func (impl *CdHandlerImpl) CheckArgoAppStatusPeriodicallyAndUpdateInDb(getPipelineDeployedBeforeMinutes int, getPipelineDeployedWithinHours int) error {
168+
pipelines, err := impl.pipelineRepository.GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(getPipelineDeployedBeforeMinutes, getPipelineDeployedWithinHours)
169169
if err != nil {
170170
impl.Logger.Errorw("error in getting pipelines having latest trigger stuck in non terminal statuses", "err", err)
171171
return err

0 commit comments

Comments
 (0)