Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CdWorkflowRepository interface {
FindCdWorkflowMetaByEnvironmentId(appId int, environmentId int, offset int, size int) ([]CdWorkflowRunner, error)
FindCdWorkflowMetaByPipelineId(pipelineId int, offset int, size int) ([]CdWorkflowRunner, error)
FindArtifactByPipelineIdAndRunnerType(pipelineId int, runnerType apiBean.WorkflowType, limit int, runnerStatuses []string) ([]CdWorkflowRunner, error)
SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error)
SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error
UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error
UpdateIsArtifactUploaded(wfrId int, isArtifactUploaded workflow.ArtifactUploadedType) error
GetPreviousQueuedRunners(cdWfrId, pipelineId int) ([]*CdWorkflowRunner, error)
Expand Down Expand Up @@ -435,9 +435,11 @@ func (impl *CdWorkflowRepositoryImpl) FindLastPreOrPostTriggeredByEnvironmentId(
return wfr, err
}

func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error) {
err := tx.Insert(wfr)
return wfr, err
func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error {
if tx == nil {
return impl.dbConnection.Insert(wfr)
}
return tx.Insert(wfr)
}

func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ func (impl *HandlerServiceImpl) ManualCdTrigger(triggerContext bean.TriggerConte
AuditLog: sql.AuditLog{CreatedOn: triggeredAt, CreatedBy: overrideRequest.UserId, UpdatedOn: triggeredAt, UpdatedBy: overrideRequest.UserId},
ReferenceId: triggerContext.ReferenceId,
}
savedWfr, err := impl.cdWorkflowRunnerService.SaveCDWorkflowRunnerWithStage(runner)
err = impl.cdWorkflowRunnerService.SaveWfr(nil, runner)
if err != nil {
impl.logger.Errorw("err in creating cdWorkflowRunner, ManualCdTrigger", "cdWorkflowId", cdWorkflowId, "err", err)
return 0, "", nil, err
}
runner.CdWorkflow = &pipelineConfig.CdWorkflow{
Pipeline: cdPipeline,
}
overrideRequest.WfrId = savedWfr.Id
overrideRequest.WfrId = runner.Id
overrideRequest.CdWorkflowId = cdWorkflowId
// creating cd pipeline status timeline for deployment initialisation
timeline := impl.pipelineStatusTimelineService.NewDevtronAppPipelineStatusTimelineDbObject(runner.Id, timelineStatus.TIMELINE_STATUS_DEPLOYMENT_INITIATED, timelineStatus.TIMELINE_DESCRIPTION_DEPLOYMENT_INITIATED, overrideRequest.UserId)
Expand Down Expand Up @@ -419,7 +419,7 @@ func (impl *HandlerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
AuditLog: sql.AuditLog{CreatedOn: triggeredAt, CreatedBy: triggeredBy, UpdatedOn: triggeredAt, UpdatedBy: triggeredBy},
ReferenceId: request.TriggerContext.ReferenceId,
}
savedWfr, err := impl.cdWorkflowRunnerService.SaveCDWorkflowRunnerWithStage(runner)
err := impl.cdWorkflowRunnerService.SaveWfr(nil, runner)
if err != nil {
return err
}
Expand Down Expand Up @@ -448,7 +448,7 @@ func (impl *HandlerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
impl.logger.Errorw("validation error deployment request", "cdWfr", runner.Id, "err", validationErr)
return validationErr
}
releaseErr := impl.TriggerCD(ctx, artifact, cdWf.Id, savedWfr.Id, pipeline, envDeploymentConfig, triggeredAt, triggeredBy)
releaseErr := impl.TriggerCD(ctx, artifact, cdWf.Id, runner.Id, pipeline, envDeploymentConfig, triggeredAt, triggeredBy)
// if releaseErr found, then the mark current deployment Failed and return
if releaseErr != nil {
err := impl.cdWorkflowCommonService.MarkCurrentDeploymentFailed(runner, releaseErr, triggeredBy)
Expand Down
8 changes: 7 additions & 1 deletion pkg/workflow/cd/CdWorkflowRunnerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (
"github.com/devtron-labs/devtron/pkg/workflow/cd/adapter"
"github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
"github.com/devtron-labs/devtron/util"
"github.com/go-pg/pg"
"go.uber.org/zap"
)

type CdWorkflowRunnerService interface {
UpdateWfr(dto *bean.CdWorkflowRunnerDto, updatedBy int) error
SaveWfr(tx *pg.Tx, wfr *pipelineConfig.CdWorkflowRunner) error
UpdateIsArtifactUploaded(wfrId int, isArtifactUploaded bool) error
SaveCDWorkflowRunnerWithStage(wfr *pipelineConfig.CdWorkflowRunner) (*pipelineConfig.CdWorkflowRunner, error)
UpdateCdWorkflowRunnerWithStage(wfr *pipelineConfig.CdWorkflowRunner) error
Expand Down Expand Up @@ -103,7 +105,7 @@ func (impl *CdWorkflowRunnerServiceImpl) SaveCDWorkflowRunnerWithStage(wfr *pipe
if impl.config.EnableWorkflowExecutionStage {
wfr.Status = cdWorkflow.WorkflowWaitingToStart
}
wfr, err = impl.cdWorkflowRepository.SaveWorkFlowRunnerWithTx(wfr, tx)
err = impl.cdWorkflowRepository.SaveWorkFlowRunnerWithTx(wfr, tx)
if err != nil {
impl.logger.Errorw("error in saving workflow", "payload", wfr, "error", err)
return wfr, err
Expand Down Expand Up @@ -198,3 +200,7 @@ func (impl *CdWorkflowRunnerServiceImpl) GetPrePostWorkflowStagesByWorkflowRunne
}
return resp, nil
}

func (impl *CdWorkflowRunnerServiceImpl) SaveWfr(tx *pg.Tx, wfr *pipelineConfig.CdWorkflowRunner) error {
return impl.cdWorkflowRepository.SaveWorkFlowRunnerWithTx(wfr, tx)
}
Loading