Skip to content

Commit 8c993ce

Browse files
authored
cdworflow read service (#6172)
1 parent c93ad53 commit 8c993ce

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

pkg/eventProcessor/in/WorkflowEventProcessorService.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"github.com/devtron-labs/devtron/pkg/workflow/cd"
5050
"github.com/devtron-labs/devtron/pkg/workflow/cd/adapter"
5151
cdWorkflowBean "github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
52+
"github.com/devtron-labs/devtron/pkg/workflow/cd/read"
5253
"github.com/devtron-labs/devtron/pkg/workflow/dag"
5354
wrokflowDagBean "github.com/devtron-labs/devtron/pkg/workflow/dag/bean"
5455
globalUtil "github.com/devtron-labs/devtron/util"
@@ -70,6 +71,7 @@ type WorkflowEventProcessorImpl struct {
7071
logger *zap.SugaredLogger
7172
pubSubClient *pubsub.PubSubClientServiceImpl
7273
cdWorkflowService cd.CdWorkflowService
74+
cdWorkflowReadService read.CdWorkflowReadService
7375
cdWorkflowRunnerService cd.CdWorkflowRunnerService
7476
workflowDagExecutor dag.WorkflowDagExecutor
7577
argoUserService argo.ArgoUserService
@@ -100,6 +102,7 @@ type WorkflowEventProcessorImpl struct {
100102
func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
101103
pubSubClient *pubsub.PubSubClientServiceImpl,
102104
cdWorkflowService cd.CdWorkflowService,
105+
cdWorkflowReadService read.CdWorkflowReadService,
103106
cdWorkflowRunnerService cd.CdWorkflowRunnerService,
104107
workflowDagExecutor dag.WorkflowDagExecutor,
105108
argoUserService argo.ArgoUserService,
@@ -121,6 +124,7 @@ func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
121124
logger: logger,
122125
pubSubClient: pubSubClient,
123126
cdWorkflowService: cdWorkflowService,
127+
cdWorkflowReadService: cdWorkflowReadService,
124128
cdWorkflowRunnerService: cdWorkflowRunnerService,
125129
argoUserService: argoUserService,
126130
ciHandler: ciHandler,
@@ -244,7 +248,7 @@ func (impl *WorkflowEventProcessorImpl) SubscribeTriggerBulkAction() error {
244248
PipelineId: cdWorkflow.PipelineId,
245249
UserId: userBean.SYSTEM_USER_ID,
246250
}
247-
latest, err := impl.cdWorkflowService.CheckIfLatestWf(cdWorkflow.PipelineId, cdWorkflow.Id)
251+
latest, err := impl.cdWorkflowReadService.CheckIfLatestWf(cdWorkflow.PipelineId, cdWorkflow.Id)
248252
if err != nil {
249253
impl.logger.Errorw("error in determining latest", "wf", cdWorkflow, "err", err)
250254
wf.WorkflowStatus = cdWorkflowModelBean.DEQUE_ERROR

pkg/workflow/cd/CdWorkflowService.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
)
2525

2626
type CdWorkflowService interface {
27-
CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error)
2827
UpdateWorkFlow(dto *bean.CdWorkflowDto) error
2928
}
3029

@@ -41,15 +40,6 @@ func NewCdWorkflowServiceImpl(logger *zap.SugaredLogger,
4140
}
4241
}
4342

44-
func (impl *CdWorkflowServiceImpl) CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error) {
45-
latest, err = impl.cdWorkflowRepository.IsLatestWf(pipelineId, cdWfId)
46-
if err != nil {
47-
impl.logger.Errorw("error in checking if wf is latest", "pipelineId", pipelineId, "cdWfId", cdWfId, "err", err)
48-
return false, err
49-
}
50-
return latest, nil
51-
}
52-
5343
func (impl *CdWorkflowServiceImpl) UpdateWorkFlow(dto *bean.CdWorkflowDto) error {
5444
dbObj := adapter.ConvertCdWorkflowDtoToDbObj(dto)
5545
err := impl.cdWorkflowRepository.UpdateWorkFlow(dbObj)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package read
2+
3+
import (
4+
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
5+
"go.uber.org/zap"
6+
)
7+
8+
type CdWorkflowReadService interface {
9+
CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error)
10+
}
11+
12+
type CdWorkflowReadServiceImpl struct {
13+
logger *zap.SugaredLogger
14+
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
15+
}
16+
17+
func NewCdWorkflowReadServiceImpl(logger *zap.SugaredLogger,
18+
cdWorkflowRepository pipelineConfig.CdWorkflowRepository) *CdWorkflowReadServiceImpl {
19+
return &CdWorkflowReadServiceImpl{
20+
logger: logger,
21+
cdWorkflowRepository: cdWorkflowRepository,
22+
}
23+
}
24+
25+
func (impl *CdWorkflowReadServiceImpl) CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error) {
26+
latest, err = impl.cdWorkflowRepository.IsLatestWf(pipelineId, cdWfId)
27+
if err != nil {
28+
impl.logger.Errorw("error in checking if wf is latest", "pipelineId", pipelineId, "cdWfId", cdWfId, "err", err)
29+
return false, err
30+
}
31+
return latest, nil
32+
}

pkg/workflow/cd/wire_workflowCd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717
package cd
1818

19-
import "github.com/google/wire"
19+
import (
20+
"github.com/devtron-labs/devtron/pkg/workflow/cd/read"
21+
"github.com/google/wire"
22+
)
2023

2124
var CdWorkflowWireSet = wire.NewSet(
2225
NewCdWorkflowCommonServiceImpl,
2326
wire.Bind(new(CdWorkflowCommonService), new(*CdWorkflowCommonServiceImpl)),
2427
NewCdWorkflowServiceImpl,
2528
wire.Bind(new(CdWorkflowService), new(*CdWorkflowServiceImpl)),
29+
read.NewCdWorkflowReadServiceImpl,
30+
wire.Bind(new(read.CdWorkflowReadService), new(*read.CdWorkflowReadServiceImpl)),
2631
NewCdWorkflowRunnerServiceImpl,
2732
wire.Bind(new(CdWorkflowRunnerService), new(*CdWorkflowRunnerServiceImpl)),
2833
)

wire_gen.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)