Skip to content

Commit 308394f

Browse files
committed
terminate workflow refactoring
1 parent c632f2d commit 308394f

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

pkg/pipeline/CdHandler.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,15 @@ func (impl *CdHandlerImpl) CancelStage(workflowRunnerId int, userId int32) (int,
175175
}
176176
}
177177
// Terminate workflow
178-
err = impl.workflowService.TerminateWorkflow(workflowRunner.ExecutorType, workflowRunner.Name, workflowRunner.Namespace, restConfig, isExtCluster, nil)
178+
cancelWfDtoRequest := &types.CancelWfRequestDto{
179+
ExecutorType: workflowRunner.ExecutorType,
180+
Name: workflowRunner.Name,
181+
Namespace: workflowRunner.Namespace,
182+
RestConfig: restConfig,
183+
IsExt: isExtCluster,
184+
Environment: nil,
185+
}
186+
err = impl.workflowService.TerminateWorkflow(cancelWfDtoRequest)
179187
if err != nil {
180188
impl.Logger.Error("cannot terminate wf runner", "err", err)
181189
return 0, err

pkg/pipeline/CiHandler.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,18 @@ func (impl *CiHandlerImpl) CancelBuild(workflowId int, forceAbort bool) (int, er
604604
return 0, err
605605
}
606606
}
607-
608607
// Terminate workflow
609-
err = impl.workflowService.TerminateWorkflow(workflow.ExecutorType, workflow.Name, workflow.Namespace, restConfig, isExt, env)
608+
cancelWfDtoRequest := &types.CancelWfRequestDto{
609+
ExecutorType: workflow.ExecutorType,
610+
Name: workflow.Name,
611+
Namespace: workflow.Namespace,
612+
RestConfig: restConfig,
613+
IsExt: isExt,
614+
Environment: env,
615+
ForceAbort: forceAbort,
616+
}
617+
// Terminate workflow
618+
err = impl.workflowService.TerminateWorkflow(cancelWfDtoRequest)
610619
if err != nil && forceAbort {
611620
impl.Logger.Errorw("error in terminating workflow, with force abort flag flag as true", "workflowName", workflow.Name, "err", err)
612621
//ignoring error in case of force abort later updating workflow with force abort

pkg/pipeline/WorkflowService.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type WorkflowService interface {
5151
GetWorkflowStatus(executorType cdWorkflow.WorkflowExecutorType, name string, namespace string, restConfig *rest.Config) (*types.WorkflowStatus, error)
5252
// ListAllWorkflows(namespace string) (*v1alpha1.WorkflowList, error)
5353
// UpdateWorkflow(wf *v1alpha1.Workflow) (*v1alpha1.Workflow, error)
54-
TerminateWorkflow(executorType cdWorkflow.WorkflowExecutorType, name string, namespace string, restConfig *rest.Config, isExt bool, environment *repository.Environment) error
54+
TerminateWorkflow(cancelWfDtoRequest *types.CancelWfRequestDto) error
5555
}
5656

5757
type WorkflowServiceImpl struct {
@@ -352,24 +352,24 @@ func (impl *WorkflowServiceImpl) GetWorkflowStatus(executorType cdWorkflow.Workf
352352
return wfStatus, err
353353
}
354354

355-
func (impl *WorkflowServiceImpl) TerminateWorkflow(executorType cdWorkflow.WorkflowExecutorType, name string, namespace string, restConfig *rest.Config, isExt bool, environment *repository.Environment) error {
356-
impl.Logger.Debugw("terminating wf", "name", name)
355+
func (impl *WorkflowServiceImpl) TerminateWorkflow(cancelWfDtoRequest *types.CancelWfRequestDto) error {
356+
impl.Logger.Debugw("terminating wf", "name", cancelWfDtoRequest.Name)
357357
var err error
358-
if executorType != "" {
359-
workflowExecutor := impl.getWorkflowExecutor(executorType)
358+
if cancelWfDtoRequest.ExecutorType != "" {
359+
workflowExecutor := impl.getWorkflowExecutor(cancelWfDtoRequest.ExecutorType)
360360
if workflowExecutor == nil {
361361
return errors.New("workflow executor not found")
362362
}
363-
if restConfig == nil {
364-
restConfig = impl.config
363+
if cancelWfDtoRequest.RestConfig == nil {
364+
cancelWfDtoRequest.RestConfig = impl.config
365365
}
366-
err = workflowExecutor.TerminateWorkflow(name, namespace, restConfig)
366+
err = workflowExecutor.TerminateWorkflow(cancelWfDtoRequest.Name, cancelWfDtoRequest.Namespace, cancelWfDtoRequest.RestConfig)
367367
} else {
368-
wfClient, err := impl.getWfClient(environment, namespace, isExt)
368+
wfClient, err := impl.getWfClient(cancelWfDtoRequest.Environment, cancelWfDtoRequest.Namespace, cancelWfDtoRequest.IsExt)
369369
if err != nil {
370370
return err
371371
}
372-
err = util.TerminateWorkflow(context.Background(), wfClient, name)
372+
err = util.TerminateWorkflow(context.Background(), wfClient, cancelWfDtoRequest.Name)
373373
}
374374
return err
375375
}

pkg/pipeline/types/CiCdConfig.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
blob_storage "github.com/devtron-labs/common-lib/blob-storage"
2626
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
2727
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
28+
"github.com/devtron-labs/devtron/pkg/cluster/repository"
2829
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
2930
v12 "k8s.io/api/core/v1"
3031
"k8s.io/client-go/rest"
@@ -37,6 +38,16 @@ import (
3738
"time"
3839
)
3940

41+
type CancelWfRequestDto struct {
42+
ExecutorType cdWorkflow.WorkflowExecutorType
43+
Name string
44+
Namespace string
45+
RestConfig *rest.Config
46+
IsExt bool
47+
Environment *repository.Environment
48+
ForceAbort bool
49+
}
50+
4051
// build infra configurations like ciTimeout,ciCpuLimit,ciMemLimit,ciCpuReq,ciMemReq are being managed by infraConfig service
4152

4253
type CiCdConfig struct {

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)