Skip to content

Commit

Permalink
feat: add Abort() option for Execution Worker, that may be useful lat…
Browse files Browse the repository at this point in the history
…er for different drivers than Kubernetes
  • Loading branch information
rangoo94 committed Oct 15, 2024
1 parent 0f18c42 commit 46e6f65
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/tcl/testworkflow-toolkit/commands/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func NewParallelCmd() *cobra.Command {
} else {
_, index := spawn.GetServiceByResourceId(err.Id)
spawn.CreateLogger("worker", descriptions[index], index, params.Count)("warning", "failed to resume", err.Error.Error())
_ = spawn.ExecutionWorker().Destroy(context.Background(), err.Id, executionworkertypes.DestroyOptions{
_ = spawn.ExecutionWorker().Abort(context.Background(), err.Id, executionworkertypes.DestroyOptions{
Namespace: namespaces[index],
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/api/v1/testworkflowexecutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *TestkubeAPI) AbortTestWorkflowExecutionHandler() fiber.Handler {
}

// Abort the Test Workflow
err = s.ExecutionWorkerClient.Destroy(ctx, execution.Id, executionworkertypes.DestroyOptions{
err = s.ExecutionWorkerClient.Abort(ctx, execution.Id, executionworkertypes.DestroyOptions{
Namespace: execution.Namespace,
})
if err != nil {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (s *TestkubeAPI) AbortAllTestWorkflowExecutionsHandler() fiber.Handler {
}

for _, execution := range executions {
err = s.ExecutionWorkerClient.Destroy(ctx, execution.Id, executionworkertypes.DestroyOptions{
err = s.ExecutionWorkerClient.Abort(ctx, execution.Id, executionworkertypes.DestroyOptions{
Namespace: execution.Namespace,
})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ type Worker interface {
// List lists all the currently deployed resources matching the criteria.
List(ctx context.Context, options ListOptions) ([]ListResultItem, error)

// Abort may either destroy or just stop the selected resource (so the data can be still accessible)
Abort(ctx context.Context, id string, options DestroyOptions) error

// Destroy gets rid of all the data for the selected resource.
Destroy(ctx context.Context, id string, options DestroyOptions) error

Expand Down

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

5 changes: 5 additions & 0 deletions pkg/testworkflows/executionworker/kubernetesworker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ func (w *worker) List(ctx context.Context, options executionworkertypes.ListOpti
return list, nil
}

func (w *worker) Abort(ctx context.Context, id string, options executionworkertypes.DestroyOptions) error {
// It may safely destroy all the resources - the trace should be still readable.
return w.Destroy(ctx, id, options)
}

func (w *worker) Destroy(ctx context.Context, id string, options executionworkertypes.DestroyOptions) (err error) {
if options.Namespace == "" {
options.Namespace, err = w.registry.GetNamespace(ctx, id)
Expand Down
2 changes: 1 addition & 1 deletion pkg/triggers/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *Service) abortRunningTestWorkflowExecutions(ctx context.Context, status
if execution.Result != nil && (execution.Result.IsRunning() || execution.Result.IsQueued() || execution.Result.IsPaused()) {
// Pro edition only (tcl protected code)
// Obtain the controller
err = s.executionWorkerClient.Destroy(ctx, execution.Id, executionworkertypes.DestroyOptions{
err = s.executionWorkerClient.Abort(ctx, execution.Id, executionworkertypes.DestroyOptions{
Namespace: s.testkubeNamespace,
})
if err != nil {
Expand Down

0 comments on commit 46e6f65

Please sign in to comment.