Skip to content

Commit

Permalink
Remove running check on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Sep 25, 2023
1 parent b8e4f65 commit 041c677
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
6 changes: 1 addition & 5 deletions packages/env-build-task-driver/internal/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,11 @@ func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) e

// DestroyTask cleans up and removes a task that has terminated.
func (d *Driver) DestroyTask(taskID string, force bool) error {
handle, ok := d.tasks.Get(taskID)
_, ok := d.tasks.Get(taskID)
if !ok {
return drivers.ErrTaskNotFound
}

if handle.IsRunning() && !force {
return errors.New("cannot destroy running task")
}

d.tasks.Delete(taskID)

return nil
Expand Down
12 changes: 3 additions & 9 deletions packages/env-build-task-driver/internal/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
}
}

func (h *taskHandle) IsRunning() bool {
h.stateLock.RLock()
defer h.stateLock.RUnlock()
return h.procState == drivers.TaskStateRunning
}

func (h *taskHandle) run(ctx context.Context, tracer trace.Tracer, docker *client.Client) {
childCtx, childSpan := tracer.Start(ctx, "run")
defer childSpan.End()
Expand All @@ -74,22 +68,22 @@ func (h *taskHandle) run(ctx context.Context, tracer trace.Tracer, docker *clien
h.completedAt = time.Now()

h.exitResult = &drivers.ExitResult{
Err: err,
Err: err,
ExitCode: 1,
}

h.stateLock.Unlock()
} else {
h.logger.Info(fmt.Sprintf("Env '%s' during build '%s' was built successfully", h.env.EnvID, h.env.BuildID))
h.stateLock.Lock()

h.exitResult = &drivers.ExitResult{
ExitCode: 0,
}

h.procState = drivers.TaskStateExited
h.completedAt = time.Now()

h.stateLock.Unlock()
}
}

0 comments on commit 041c677

Please sign in to comment.