@@ -30,12 +30,12 @@ import (
30
30
31
31
type WorkflowStatusLatestService interface {
32
32
// CI Workflow Status Latest methods
33
- SaveOrUpdateCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , ciWorkflowId int , userId int32 ) error
33
+ SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , ciWorkflowId int , userId int32 ) error
34
34
GetCiWorkflowStatusLatestByPipelineId (pipelineId int ) (* CiWorkflowStatusLatest , error )
35
35
GetCiWorkflowStatusLatestByAppId (appId int ) ([]* CiWorkflowStatusLatest , error )
36
36
37
37
// CD Workflow Status Latest methods
38
- SaveOrUpdateCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error
38
+ SaveCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error
39
39
GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (pipelineId int , workflowType string ) (* CdWorkflowStatusLatest , error )
40
40
GetCdWorkflowStatusLatestByAppId (appId int ) ([]* CdWorkflowStatusLatest , error )
41
41
GetCdWorkflowStatusLatestByPipelineId (pipelineId int ) ([]* CdWorkflowStatusLatest , error )
@@ -47,19 +47,22 @@ type WorkflowStatusLatestServiceImpl struct {
47
47
workflowStatusLatestRepository pipelineConfig.WorkflowStatusLatestRepository
48
48
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
49
49
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
50
+ ciPipelineRepository pipelineConfig.CiPipelineRepository
50
51
}
51
52
52
53
func NewWorkflowStatusLatestServiceImpl (
53
54
logger * zap.SugaredLogger ,
54
55
workflowStatusLatestRepository pipelineConfig.WorkflowStatusLatestRepository ,
55
56
ciWorkflowRepository pipelineConfig.CiWorkflowRepository ,
56
57
cdWorkflowRepository pipelineConfig.CdWorkflowRepository ,
58
+ ciPipelineRepository pipelineConfig.CiPipelineRepository ,
57
59
) * WorkflowStatusLatestServiceImpl {
58
60
return & WorkflowStatusLatestServiceImpl {
59
61
logger : logger ,
60
62
workflowStatusLatestRepository : workflowStatusLatestRepository ,
61
63
ciWorkflowRepository : ciWorkflowRepository ,
62
64
cdWorkflowRepository : cdWorkflowRepository ,
65
+ ciPipelineRepository : ciPipelineRepository ,
63
66
}
64
67
}
65
68
@@ -80,8 +83,7 @@ type CdWorkflowStatusLatest struct {
80
83
Status string `json:"status"` // Derived from cd_workflow_runner table
81
84
}
82
85
83
- // CI Workflow Status Latest methods implementation
84
- func (impl * WorkflowStatusLatestServiceImpl ) SaveOrUpdateCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , ciWorkflowId int , userId int32 ) error {
86
+ func (impl * WorkflowStatusLatestServiceImpl ) SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , ciWorkflowId int , userId int32 ) error {
85
87
// Validate required parameters
86
88
if pipelineId <= 0 {
87
89
impl .logger .Errorw ("invalid pipelineId provided" , "pipelineId" , pipelineId )
@@ -92,44 +94,22 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveOrUpdateCiWorkflowStatusLatest(
92
94
impl .logger .Errorw ("invalid ciWorkflowId provided" , "ciWorkflowId" , ciWorkflowId )
93
95
return fmt .Errorf ("invalid ciWorkflowId: %d" , ciWorkflowId )
94
96
}
95
-
96
- // If appId is not provided (0), fetch it from the CiPipeline
97
- if appId <= 0 {
98
- ciPipeline , err := impl .ciWorkflowRepository .FindById (ciWorkflowId )
99
- if err != nil {
100
- impl .logger .Errorw ("error in fetching ci workflow to get appId" , "err" , err , "ciWorkflowId" , ciWorkflowId )
101
- return err
102
- }
103
-
104
- if ciPipeline == nil {
105
- impl .logger .Errorw ("ci workflow not found" , "ciWorkflowId" , ciWorkflowId )
106
- return fmt .Errorf ("ci workflow not found with id: %d" , ciWorkflowId )
107
- }
108
-
109
- // Check if CiPipeline is loaded
110
- if ciPipeline .CiPipeline == nil {
111
- impl .logger .Errorw ("ci pipeline not loaded in ci workflow" , "ciWorkflowId" , ciWorkflowId , "ciPipelineId" , ciPipeline .CiPipelineId )
112
- return fmt .Errorf ("ci pipeline not loaded for workflow id: %d" , ciWorkflowId )
113
- }
114
-
115
- appId = ciPipeline .CiPipeline .AppId
116
- if appId <= 0 {
117
- impl .logger .Errorw ("invalid appId in ci pipeline" , "ciWorkflowId" , ciWorkflowId , "ciPipelineId" , ciPipeline .CiPipelineId , "appId" , appId )
118
- return fmt .Errorf ("invalid appId in ci pipeline: %d" , appId )
119
- }
120
-
121
- impl .logger .Debugw ("fetched appId from ci workflow" , "ciWorkflowId" , ciWorkflowId , "appId" , appId )
97
+ ciPipeline , err := impl .ciPipelineRepository .FindOneWithAppData (pipelineId )
98
+ if err != nil {
99
+ impl .logger .Errorw ("error in fetching ci pipeline for appId" , "ciPipelineId" , pipelineId , "err" , err )
100
+ return err
122
101
}
102
+ appId := ciPipeline .AppId
123
103
124
104
// Check if entry exists
125
105
existingEntry , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineId (pipelineId )
126
- if err != nil && err != pg . ErrNoRows {
106
+ if err != nil && ! util2 . IsErrNoRows ( err ) {
127
107
impl .logger .Errorw ("error in getting ci workflow status latest" , "err" , err , "pipelineId" , pipelineId )
128
108
return err
129
109
}
130
110
131
111
now := time .Now ()
132
- if err == pg . ErrNoRows {
112
+ if util2 . IsErrNoRows ( err ) {
133
113
// Create new entry
134
114
model := & pipelineConfig.CiWorkflowStatusLatest {
135
115
PipelineId : pipelineId ,
@@ -207,7 +187,7 @@ func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByAppId(ap
207
187
}
208
188
209
189
// CD Workflow Status Latest methods implementation
210
- func (impl * WorkflowStatusLatestServiceImpl ) SaveOrUpdateCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error {
190
+ func (impl * WorkflowStatusLatestServiceImpl ) SaveCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error {
211
191
// Validate required parameters
212
192
if pipelineId <= 0 {
213
193
impl .logger .Errorw ("invalid pipelineId provided" , "pipelineId" , pipelineId )
0 commit comments