66 pubsub "github.com/devtron-labs/common-lib/pubsub-lib"
77 "github.com/devtron-labs/devtron/api/bean"
88 client2 "github.com/devtron-labs/devtron/client/events"
9+ "github.com/devtron-labs/devtron/internal/middleware"
910 "github.com/devtron-labs/devtron/internal/sql/repository"
1011 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
1112 "github.com/devtron-labs/devtron/pkg/app"
@@ -16,6 +17,7 @@ import (
1617 "github.com/robfig/cron/v3"
1718 "go.uber.org/zap"
1819 "strconv"
20+ "time"
1921)
2022
2123type CdApplicationStatusUpdateHandler interface {
@@ -46,6 +48,19 @@ type CdApplicationStatusUpdateHandlerImpl struct {
4648 installedAppVersionRepository repository2.InstalledAppRepository
4749}
4850
51+ type CronLoggerImpl struct {
52+ logger * zap.SugaredLogger
53+ }
54+
55+ func (impl * CronLoggerImpl ) Info (msg string , keysAndValues ... interface {}) {
56+ impl .logger .Infow (msg , keysAndValues ... )
57+ }
58+
59+ func (impl * CronLoggerImpl ) Error (err error , msg string , keysAndValues ... interface {}) {
60+ keysAndValues = append ([]interface {}{"err" , err }, keysAndValues ... )
61+ impl .logger .Errorw (msg , keysAndValues ... )
62+ }
63+
4964func NewCdApplicationStatusUpdateHandlerImpl (logger * zap.SugaredLogger , appService app.AppService ,
5065 workflowDagExecutor pipeline.WorkflowDagExecutor , installedAppService service.InstalledAppService ,
5166 CdHandler pipeline.CdHandler , AppStatusConfig * app.AppServiceConfig , pubsubClient * pubsub.PubSubClientServiceImpl ,
@@ -54,8 +69,9 @@ func NewCdApplicationStatusUpdateHandlerImpl(logger *zap.SugaredLogger, appServi
5469 cdWorkflowRepository pipelineConfig.CdWorkflowRepository ,
5570 pipelineRepository pipelineConfig.PipelineRepository , installedAppVersionHistoryRepository repository2.InstalledAppVersionHistoryRepository ,
5671 installedAppVersionRepository repository2.InstalledAppRepository ) * CdApplicationStatusUpdateHandlerImpl {
72+ cronLogger := & CronLoggerImpl {logger : logger }
5773 cron := cron .New (
58- cron .WithChain ())
74+ cron .WithChain (cron . SkipIfStillRunning ( cronLogger ) ))
5975 cron .Start ()
6076 impl := & CdApplicationStatusUpdateHandlerImpl {
6177 logger : logger ,
@@ -141,6 +157,8 @@ func (impl *CdApplicationStatusUpdateHandlerImpl) Subscribe() error {
141157}
142158
143159func (impl * CdApplicationStatusUpdateHandlerImpl ) HelmApplicationStatusUpdate () {
160+ cronProcessStartTime := time .Now ()
161+ defer middleware .DeploymentStatusCronDuration .WithLabelValues (pipeline .DEVTRON_APP_HELM_PIPELINE_STATUS_UPDATE_CRON ).Observe (time .Since (cronProcessStartTime ).Seconds ())
144162 HelmPipelineStatusCheckEligibleTime , err := strconv .Atoi (impl .AppStatusConfig .HelmPipelineStatusCheckEligibleTime )
145163 if err != nil {
146164 impl .logger .Errorw ("error in converting string to int" , "err" , err )
@@ -155,6 +173,11 @@ func (impl *CdApplicationStatusUpdateHandlerImpl) HelmApplicationStatusUpdate()
155173}
156174
157175func (impl * CdApplicationStatusUpdateHandlerImpl ) ArgoApplicationStatusUpdate () {
176+ cronProcessStartTime := time .Now ()
177+ defer middleware .DeploymentStatusCronDuration .WithLabelValues (pipeline .DEVTRON_APP_HELM_PIPELINE_STATUS_UPDATE_CRON ).Observe (time .Since (cronProcessStartTime ).Seconds ())
178+ //TODO: remove below cron with division of cron for argo pipelines of devtron-apps and helm-apps
179+ defer middleware .DeploymentStatusCronDuration .WithLabelValues (pipeline .HELM_APP_ARGO_PIPELINE_STATUS_UPDATE_CRON ).Observe (time .Since (cronProcessStartTime ).Seconds ())
180+
158181 getPipelineDeployedBeforeMinutes , err := strconv .Atoi (impl .AppStatusConfig .PipelineDegradedTime )
159182 if err != nil {
160183 impl .logger .Errorw ("error in converting string to int" , "err" , err )
0 commit comments