Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: cdworflow read service #6172

Merged
merged 2 commits into from
Dec 12, 2024
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
6 changes: 5 additions & 1 deletion pkg/eventProcessor/in/WorkflowEventProcessorService.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/devtron-labs/devtron/pkg/workflow/cd"
"github.com/devtron-labs/devtron/pkg/workflow/cd/adapter"
cdWorkflowBean "github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
"github.com/devtron-labs/devtron/pkg/workflow/cd/read"
"github.com/devtron-labs/devtron/pkg/workflow/dag"
wrokflowDagBean "github.com/devtron-labs/devtron/pkg/workflow/dag/bean"
globalUtil "github.com/devtron-labs/devtron/util"
Expand All @@ -70,6 +71,7 @@ type WorkflowEventProcessorImpl struct {
logger *zap.SugaredLogger
pubSubClient *pubsub.PubSubClientServiceImpl
cdWorkflowService cd.CdWorkflowService
cdWorkflowReadService read.CdWorkflowReadService
cdWorkflowRunnerService cd.CdWorkflowRunnerService
workflowDagExecutor dag.WorkflowDagExecutor
argoUserService argo.ArgoUserService
Expand Down Expand Up @@ -100,6 +102,7 @@ type WorkflowEventProcessorImpl struct {
func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
pubSubClient *pubsub.PubSubClientServiceImpl,
cdWorkflowService cd.CdWorkflowService,
cdWorkflowReadService read.CdWorkflowReadService,
cdWorkflowRunnerService cd.CdWorkflowRunnerService,
workflowDagExecutor dag.WorkflowDagExecutor,
argoUserService argo.ArgoUserService,
Expand All @@ -121,6 +124,7 @@ func NewWorkflowEventProcessorImpl(logger *zap.SugaredLogger,
logger: logger,
pubSubClient: pubSubClient,
cdWorkflowService: cdWorkflowService,
cdWorkflowReadService: cdWorkflowReadService,
cdWorkflowRunnerService: cdWorkflowRunnerService,
argoUserService: argoUserService,
ciHandler: ciHandler,
Expand Down Expand Up @@ -244,7 +248,7 @@ func (impl *WorkflowEventProcessorImpl) SubscribeTriggerBulkAction() error {
PipelineId: cdWorkflow.PipelineId,
UserId: userBean.SYSTEM_USER_ID,
}
latest, err := impl.cdWorkflowService.CheckIfLatestWf(cdWorkflow.PipelineId, cdWorkflow.Id)
latest, err := impl.cdWorkflowReadService.CheckIfLatestWf(cdWorkflow.PipelineId, cdWorkflow.Id)
if err != nil {
impl.logger.Errorw("error in determining latest", "wf", cdWorkflow, "err", err)
wf.WorkflowStatus = cdWorkflowModelBean.DEQUE_ERROR
Expand Down
10 changes: 0 additions & 10 deletions pkg/workflow/cd/CdWorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
)

type CdWorkflowService interface {
CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error)
UpdateWorkFlow(dto *bean.CdWorkflowDto) error
}

Expand All @@ -41,15 +40,6 @@ func NewCdWorkflowServiceImpl(logger *zap.SugaredLogger,
}
}

func (impl *CdWorkflowServiceImpl) CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error) {
latest, err = impl.cdWorkflowRepository.IsLatestWf(pipelineId, cdWfId)
if err != nil {
impl.logger.Errorw("error in checking if wf is latest", "pipelineId", pipelineId, "cdWfId", cdWfId, "err", err)
return false, err
}
return latest, nil
}

func (impl *CdWorkflowServiceImpl) UpdateWorkFlow(dto *bean.CdWorkflowDto) error {
dbObj := adapter.ConvertCdWorkflowDtoToDbObj(dto)
err := impl.cdWorkflowRepository.UpdateWorkFlow(dbObj)
Expand Down
32 changes: 32 additions & 0 deletions pkg/workflow/cd/read/CdWorkflowReadService.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package read

import (
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"go.uber.org/zap"
)

type CdWorkflowReadService interface {
CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error)
}

type CdWorkflowReadServiceImpl struct {
logger *zap.SugaredLogger
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
}

func NewCdWorkflowReadServiceImpl(logger *zap.SugaredLogger,
cdWorkflowRepository pipelineConfig.CdWorkflowRepository) *CdWorkflowReadServiceImpl {
return &CdWorkflowReadServiceImpl{
logger: logger,
cdWorkflowRepository: cdWorkflowRepository,
}
}

func (impl *CdWorkflowReadServiceImpl) CheckIfLatestWf(pipelineId, cdWfId int) (latest bool, err error) {
latest, err = impl.cdWorkflowRepository.IsLatestWf(pipelineId, cdWfId)
if err != nil {
impl.logger.Errorw("error in checking if wf is latest", "pipelineId", pipelineId, "cdWfId", cdWfId, "err", err)
return false, err
}
return latest, nil
}
7 changes: 6 additions & 1 deletion pkg/workflow/cd/wire_workflowCd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package cd

import "github.com/google/wire"
import (
"github.com/devtron-labs/devtron/pkg/workflow/cd/read"
"github.com/google/wire"
)

var CdWorkflowWireSet = wire.NewSet(
NewCdWorkflowCommonServiceImpl,
wire.Bind(new(CdWorkflowCommonService), new(*CdWorkflowCommonServiceImpl)),
NewCdWorkflowServiceImpl,
wire.Bind(new(CdWorkflowService), new(*CdWorkflowServiceImpl)),
read.NewCdWorkflowReadServiceImpl,
wire.Bind(new(read.CdWorkflowReadService), new(*read.CdWorkflowReadServiceImpl)),
NewCdWorkflowRunnerServiceImpl,
wire.Bind(new(CdWorkflowRunnerService), new(*CdWorkflowRunnerServiceImpl)),
)
6 changes: 4 additions & 2 deletions wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading