@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
- "net/url"
24
23
"strconv"
25
24
"time"
26
25
@@ -47,7 +46,6 @@ import (
47
46
48
47
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
49
48
"github.com/caarlos0/env"
50
- "github.com/devtron-labs/common-lib/async"
51
49
k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
52
50
"github.com/devtron-labs/common-lib/utils/k8s/health"
53
51
"github.com/devtron-labs/devtron/api/bean"
@@ -126,7 +124,7 @@ type AppServiceImpl struct {
126
124
deploymentConfigService common2.DeploymentConfigService
127
125
envConfigOverrideReadService read.EnvConfigOverrideService
128
126
cdWorkflowRunnerService cd.CdWorkflowRunnerService
129
- asyncRunnable * async. Runnable
127
+ deploymentEventHandler DeploymentEventHandler
130
128
}
131
129
132
130
type AppService interface {
@@ -135,7 +133,6 @@ type AppService interface {
135
133
GetConfigMapAndSecretJson (appId int , envId int ) ([]byte , error )
136
134
UpdateCdWorkflowRunnerByACDObject (app * v1alpha1.Application , cdWfrId int , updateTimedOutStatus bool ) error
137
135
UpdateDeploymentStatusForGitOpsPipelines (app * v1alpha1.Application , applicationClusterId int , statusTime time.Time , isAppStore bool ) (bool , bool , * chartConfig.PipelineOverride , error )
138
- WriteCDSuccessEvent (appId int , envId int , override * chartConfig.PipelineOverride )
139
136
CreateGitOpsRepo (app * app.App , targetRevision string , userId int32 ) (gitopsRepoName string , chartGitAttr * commonBean.ChartGitAttribute , err error )
140
137
141
138
// TODO: move inside reader service
@@ -168,7 +165,7 @@ func NewAppService(
168
165
deploymentConfigService common2.DeploymentConfigService ,
169
166
envConfigOverrideReadService read.EnvConfigOverrideService ,
170
167
cdWorkflowRunnerService cd.CdWorkflowRunnerService ,
171
- asyncRunnable * async. Runnable ) * AppServiceImpl {
168
+ deploymentEventHandler DeploymentEventHandler ) * AppServiceImpl {
172
169
appServiceImpl := & AppServiceImpl {
173
170
mergeUtil : mergeUtil ,
174
171
pipelineOverrideRepository : pipelineOverrideRepository ,
@@ -199,7 +196,7 @@ func NewAppService(
199
196
deploymentConfigService : deploymentConfigService ,
200
197
envConfigOverrideReadService : envConfigOverrideReadService ,
201
198
cdWorkflowRunnerService : cdWorkflowRunnerService ,
202
- asyncRunnable : asyncRunnable ,
199
+ deploymentEventHandler : deploymentEventHandler ,
203
200
}
204
201
return appServiceImpl
205
202
}
@@ -309,6 +306,7 @@ func (impl *AppServiceImpl) UpdateDeploymentStatusForGitOpsPipelines(app *v1alph
309
306
impl .logger .Errorw ("error on update cd workflow runner" , "CdWorkflowId" , pipelineOverride .CdWorkflowId , "status" , cdWorkflow2 .WorkflowTimedOut , "err" , err )
310
307
return isSucceeded , isTimelineUpdated , pipelineOverride , err
311
308
}
309
+ impl .deploymentEventHandler .WriteCDNotificationEventAsync (cdPipeline .AppId , cdPipeline .EnvironmentId , pipelineOverride , eventUtil .Fail )
312
310
return isSucceeded , isTimelineUpdated , pipelineOverride , nil
313
311
}
314
312
if reconciledAt .IsZero () || (kubectlSyncedTimeline != nil && kubectlSyncedTimeline .Id > 0 && reconciledAt .After (kubectlSyncedTimeline .StatusTime )) {
@@ -325,7 +323,7 @@ func (impl *AppServiceImpl) UpdateDeploymentStatusForGitOpsPipelines(app *v1alph
325
323
}
326
324
if isSucceeded {
327
325
impl .logger .Infow ("writing cd success event" , "gitHash" , gitHash , "pipelineOverride" , pipelineOverride )
328
- impl .asyncRunnable . Execute ( func () { impl . WriteCDSuccessEvent ( cdPipeline .AppId , cdPipeline .EnvironmentId , pipelineOverride ) } )
326
+ impl .deploymentEventHandler . WriteCDNotificationEventAsync ( cdPipeline .AppId , cdPipeline .EnvironmentId , pipelineOverride , eventUtil . Success )
329
327
}
330
328
} else {
331
329
impl .logger .Debugw ("event received for older triggered revision" , "gitHash" , gitHash )
@@ -773,23 +771,6 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
773
771
return isTimelineUpdated , isTimelineTimedOut , kubectlApplySyncedTimeline , nil
774
772
}
775
773
776
- func (impl * AppServiceImpl ) WriteCDSuccessEvent (appId int , envId int , override * chartConfig.PipelineOverride ) {
777
- event , _ := impl .eventFactory .Build (eventUtil .Success , & override .PipelineId , appId , & envId , eventUtil .CD )
778
- impl .logger .Debugw ("event WriteCDSuccessEvent" , "event" , event , "override" , override )
779
- event = impl .eventFactory .BuildExtraCDData (event , nil , override .Id , bean .CD_WORKFLOW_TYPE_DEPLOY )
780
- _ , evtErr := impl .eventClient .WriteNotificationEvent (event )
781
- if evtErr != nil {
782
- impl .logger .Errorw ("error in writing event" , "event" , event , "err" , evtErr )
783
- }
784
- }
785
-
786
- func (impl * AppServiceImpl ) BuildCDSuccessPayload (appName string , environmentName string ) * client.Payload {
787
- payload := & client.Payload {}
788
- payload .AppName = appName
789
- payload .EnvName = environmentName
790
- return payload
791
- }
792
-
793
774
type ValuesOverrideResponse struct {
794
775
MergedValues string
795
776
ReleaseOverrideJSON string
@@ -887,29 +868,6 @@ type PipelineMaterialInfo struct {
887
868
CommitHash string
888
869
}
889
870
890
- func buildCDTriggerEvent (impl * AppServiceImpl , overrideRequest * bean.ValuesOverrideRequest , pipeline * pipelineConfig.Pipeline ,
891
- envOverride * chartConfig.EnvConfigOverride , materialInfo map [string ]string , artifact * repository.CiArtifact ) client.Event {
892
- event , _ := impl .eventFactory .Build (eventUtil .Trigger , & pipeline .Id , pipeline .AppId , & pipeline .EnvironmentId , eventUtil .CD )
893
- return event
894
- }
895
-
896
- func (impl * AppServiceImpl ) BuildPayload (overrideRequest * bean.ValuesOverrideRequest , pipeline * pipelineConfig.Pipeline ,
897
- envOverride * chartConfig.EnvConfigOverride , materialInfo map [string ]string , artifact * repository.CiArtifact ) * client.Payload {
898
- payload := & client.Payload {}
899
- payload .AppName = pipeline .App .AppName
900
- payload .PipelineName = pipeline .Name
901
- payload .EnvName = envOverride .Environment .Name
902
-
903
- var revision string
904
- for _ , v := range materialInfo {
905
- revision = v
906
- break
907
- }
908
- payload .Source = url .PathEscape (revision )
909
- payload .DockerImageUrl = artifact .Image
910
- return payload
911
- }
912
-
913
871
type ReleaseAttributes struct {
914
872
Name string
915
873
Tag string
0 commit comments