Skip to content

Commit b97e7e4

Browse files
committed
Decouple workflow status management by deriving status from respective workflow tables.
1 parent 87521d5 commit b97e7e4

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

internal/sql/repository/pipelineConfig/WorkflowStatusLatestRepository.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type CiWorkflowStatusLatest struct {
5858
PipelineId int `sql:"pipeline_id"`
5959
AppId int `sql:"app_id"`
6060
CiWorkflowId int `sql:"ci_workflow_id"`
61-
Status string `sql:"status"`
6261
sql.AuditLog
6362
}
6463

@@ -71,7 +70,6 @@ type CdWorkflowStatusLatest struct {
7170
EnvironmentId int `sql:"environment_id"`
7271
WorkflowType string `sql:"workflow_type"`
7372
WorkflowRunnerId int `sql:"workflow_runner_id"`
74-
Status string `sql:"status"`
7573
sql.AuditLog
7674
}
7775

pkg/workflow/status/WorkflowStatusLatestService.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import (
2828

2929
type WorkflowStatusLatestService interface {
3030
// CI Workflow Status Latest methods
31-
SaveOrUpdateCiWorkflowStatusLatest(pipelineId, appId, ciWorkflowId int, status string, userId int32) error
31+
SaveOrUpdateCiWorkflowStatusLatest(pipelineId, appId, ciWorkflowId int, userId int32) error
3232
GetCiWorkflowStatusLatestByPipelineId(pipelineId int) (*CiWorkflowStatusLatest, error)
3333
GetCiWorkflowStatusLatestByAppId(appId int) ([]*CiWorkflowStatusLatest, error)
3434

3535
// CD Workflow Status Latest methods
36-
SaveOrUpdateCdWorkflowStatusLatest(pipelineId, appId, environmentId, workflowRunnerId int, workflowType, status string, userId int32) error
36+
SaveOrUpdateCdWorkflowStatusLatest(pipelineId, appId, environmentId, workflowRunnerId int, workflowType string, userId int32) error
3737
GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error)
3838
GetCdWorkflowStatusLatestByAppId(appId int) ([]*CdWorkflowStatusLatest, error)
3939
GetCdWorkflowStatusLatestByPipelineId(pipelineId int) ([]*CdWorkflowStatusLatest, error)
@@ -65,7 +65,7 @@ type CiWorkflowStatusLatest struct {
6565
PipelineId int `json:"pipelineId"`
6666
AppId int `json:"appId"`
6767
CiWorkflowId int `json:"ciWorkflowId"`
68-
Status string `json:"status"`
68+
Status string `json:"status"` // Derived from ci_workflow table
6969
}
7070

7171
type CdWorkflowStatusLatest struct {
@@ -74,11 +74,11 @@ type CdWorkflowStatusLatest struct {
7474
EnvironmentId int `json:"environmentId"`
7575
WorkflowType string `json:"workflowType"`
7676
WorkflowRunnerId int `json:"workflowRunnerId"`
77-
Status string `json:"status"`
77+
Status string `json:"status"` // Derived from cd_workflow_runner table
7878
}
7979

8080
// CI Workflow Status Latest methods implementation
81-
func (impl *WorkflowStatusLatestServiceImpl) SaveOrUpdateCiWorkflowStatusLatest(pipelineId, appId, ciWorkflowId int, status string, userId int32) error {
81+
func (impl *WorkflowStatusLatestServiceImpl) SaveOrUpdateCiWorkflowStatusLatest(pipelineId, appId, ciWorkflowId int, userId int32) error {
8282
// Check if entry exists
8383
existingEntry, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineId(pipelineId)
8484
if err != nil && err != pg.ErrNoRows {
@@ -93,7 +93,6 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveOrUpdateCiWorkflowStatusLatest(
9393
PipelineId: pipelineId,
9494
AppId: appId,
9595
CiWorkflowId: ciWorkflowId,
96-
Status: status,
9796
}
9897
model.CreatedBy = userId
9998
model.CreatedOn = now
@@ -104,7 +103,6 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveOrUpdateCiWorkflowStatusLatest(
104103
} else {
105104
// Update existing entry
106105
existingEntry.CiWorkflowId = ciWorkflowId
107-
existingEntry.Status = status
108106
existingEntry.UpdatedBy = userId
109107
existingEntry.UpdatedOn = now
110108

@@ -123,11 +121,18 @@ func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByPipeline
123121
return nil, err
124122
}
125123

124+
// Get status from ci_workflow table
125+
ciWorkflow, err := impl.ciWorkflowRepository.FindById(model.CiWorkflowId)
126+
if err != nil {
127+
impl.logger.Errorw("error in getting ci workflow", "err", err, "ciWorkflowId", model.CiWorkflowId)
128+
return nil, err
129+
}
130+
126131
return &CiWorkflowStatusLatest{
127132
PipelineId: model.PipelineId,
128133
AppId: model.AppId,
129134
CiWorkflowId: model.CiWorkflowId,
130-
Status: model.Status,
135+
Status: ciWorkflow.Status,
131136
}, nil
132137
}
133138

@@ -140,11 +145,18 @@ func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByAppId(ap
140145

141146
var result []*CiWorkflowStatusLatest
142147
for _, model := range models {
148+
// Get status from ci_workflow table
149+
ciWorkflow, err := impl.ciWorkflowRepository.FindById(model.CiWorkflowId)
150+
if err != nil {
151+
impl.logger.Errorw("error in getting ci workflow", "err", err, "ciWorkflowId", model.CiWorkflowId)
152+
continue // Skip this entry if we can't get the workflow
153+
}
154+
143155
result = append(result, &CiWorkflowStatusLatest{
144156
PipelineId: model.PipelineId,
145157
AppId: model.AppId,
146158
CiWorkflowId: model.CiWorkflowId,
147-
Status: model.Status,
159+
Status: ciWorkflow.Status,
148160
})
149161
}
150162

scripts/sql/34203900_workflow_status_latest_tables.up.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ CREATE TABLE IF NOT EXISTS "public"."ci_workflow_status_latest" (
99
"pipeline_id" int4 NOT NULL,
1010
"app_id" int4 NOT NULL,
1111
"ci_workflow_id" int4 NOT NULL,
12-
"status" varchar(50) NOT NULL,
1312
"created_on" timestamptz NOT NULL,
1413
"created_by" int4 NOT NULL,
1514
"updated_on" timestamptz NOT NULL,
@@ -29,7 +28,6 @@ CREATE TABLE IF NOT EXISTS "public"."cd_workflow_status_latest" (
2928
"environment_id" int4 NOT NULL,
3029
"workflow_type" varchar(20) NOT NULL, -- PRE, DEPLOY, POST
3130
"workflow_runner_id" int4 NOT NULL,
32-
"status" varchar(50) NOT NULL,
3331
"created_on" timestamptz NOT NULL,
3432
"created_by" int4 NOT NULL,
3533
"updated_on" timestamptz NOT NULL,

0 commit comments

Comments
 (0)