Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ func InitializeApp() (*App, error) {
cron.NewCdApplicationStatusUpdateHandlerImpl,
wire.Bind(new(cron.CdApplicationStatusUpdateHandler), new(*cron.CdApplicationStatusUpdateHandlerImpl)),

cron.GetCiWorkflowStatusUpdateConfig,
cron.NewCiStatusUpdateCronImpl,
wire.Bind(new(cron.CiStatusUpdateCron), new(*cron.CiStatusUpdateCronImpl)),


restHandler.NewPipelineStatusTimelineRestHandlerImpl,
wire.Bind(new(restHandler.PipelineStatusTimelineRestHandler), new(*restHandler.PipelineStatusTimelineRestHandlerImpl)),

Expand Down
5 changes: 4 additions & 1 deletion api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type MuxRouter struct {
webhookHelmRouter webhookHelm.WebhookHelmRouter
globalCMCSRouter GlobalCMCSRouter
userTerminalAccessRouter terminal2.UserTerminalAccessRouter
ciStatusUpdateCron cron.CiStatusUpdateCron
}

func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, PipelineConfigRouter PipelineConfigRouter,
Expand All @@ -141,7 +142,8 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, P
globalPluginRouter GlobalPluginRouter, moduleRouter module.ModuleRouter,
serverRouter server.ServerRouter, apiTokenRouter apiToken.ApiTokenRouter,
helmApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler, k8sCapacityRouter k8s.K8sCapacityRouter,
webhookHelmRouter webhookHelm.WebhookHelmRouter, globalCMCSRouter GlobalCMCSRouter, userTerminalAccessRouter terminal2.UserTerminalAccessRouter) *MuxRouter {
webhookHelmRouter webhookHelm.WebhookHelmRouter, globalCMCSRouter GlobalCMCSRouter,
userTerminalAccessRouter terminal2.UserTerminalAccessRouter, ciStatusUpdateCron cron.CiStatusUpdateCron) *MuxRouter {
r := &MuxRouter{
Router: mux.NewRouter(),
HelmRouter: HelmRouter,
Expand Down Expand Up @@ -207,6 +209,7 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, P
webhookHelmRouter: webhookHelmRouter,
globalCMCSRouter: globalCMCSRouter,
userTerminalAccessRouter: userTerminalAccessRouter,
ciStatusUpdateCron: ciStatusUpdateCron,
}
return r
}
Expand Down
79 changes: 79 additions & 0 deletions client/cron/CiStatusUpdateCron.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cron

import (
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/pipeline"
"github.com/robfig/cron/v3"
"go.uber.org/zap"
"strconv"
)

type CiStatusUpdateCron interface {
UpdateCiWorkflowStatusFailedCron()
}

type CiStatusUpdateCronImpl struct {
logger *zap.SugaredLogger
cron *cron.Cron
appService app.AppService
ciWorkflowStatusUpdateConfig *CiWorkflowStatusUpdateConfig
ciPipelineRepository pipelineConfig.CiPipelineRepository
ciHandler pipeline.CiHandler
}

func NewCiStatusUpdateCronImpl(logger *zap.SugaredLogger, appService app.AppService,
ciWorkflowStatusUpdateConfig *CiWorkflowStatusUpdateConfig, ciPipelineRepository pipelineConfig.CiPipelineRepository,
ciHandler pipeline.CiHandler) *CiStatusUpdateCronImpl {
cron := cron.New(
cron.WithChain())
cron.Start()
impl := &CiStatusUpdateCronImpl{
logger: logger,
cron: cron,
appService: appService,
ciWorkflowStatusUpdateConfig: ciWorkflowStatusUpdateConfig,
ciPipelineRepository: ciPipelineRepository,
ciHandler: ciHandler,
}

// execute periodically, update ci workflow status for failed process
_, err := cron.AddFunc(ciWorkflowStatusUpdateConfig.CiWorkflowStatusUpdateCron, impl.UpdateCiWorkflowStatusFailedCron)
if err != nil {
logger.Errorw("error while configure cron job for ci workflow status update", "err", err)
return impl
}
return impl
}

type CiWorkflowStatusUpdateConfig struct {
CiWorkflowStatusUpdateCron string `env:"CI_WORKFLOW_STATUS_UPDATE_CRON" envDefault:"*/5 * * * *"`
TimeoutForFailedCiBuild string `env:"TIMEOUT_FOR_FAILED_CI_BUILD" envDefault:"15"` //in minutes
}

func GetCiWorkflowStatusUpdateConfig() (*CiWorkflowStatusUpdateConfig, error) {
cfg := &CiWorkflowStatusUpdateConfig{}
err := env.Parse(cfg)
if err != nil {
fmt.Println("failed to parse ci workflow status update config: " + err.Error())
return nil, err
}
return cfg, nil
}

// UpdateCiWorkflowStatusFailedCron this function will execute periodically
func (impl *CiStatusUpdateCronImpl) UpdateCiWorkflowStatusFailedCron() {
timeoutForFailureCiBuild, err := strconv.Atoi(impl.ciWorkflowStatusUpdateConfig.TimeoutForFailedCiBuild)
if err != nil {
impl.logger.Errorw("error in converting string to int", "err", err)
return
}
err = impl.ciHandler.UpdateCiWorkflowStatusFailure(timeoutForFailureCiBuild)
if err != nil {
impl.logger.Errorw("error in updating ci workflow status for failed workflows", "err", err)
return
}
return
}
Loading