Skip to content

cancel all possible tasks#93

Merged
wlggraham merged 4 commits intomainfrom
ecs_plugin_cancel_jobs_fix
Feb 20, 2026
Merged

cancel all possible tasks#93
wlggraham merged 4 commits intomainfrom
ecs_plugin_cancel_jobs_fix

Conversation

@wlggraham
Copy link
Contributor

The Cleanup() function would use the task_count from the command context, which can be overridden by the job context. This means that any jobs excess of the command context were not being canceled properly.

The new solution takes the max_tasks from the cluster context and tries to cancel any potential job in that range. For example, if the max_tasks is 3, but the job context only specified 1, then it would try stopping all of the following tasks (searched for by the startedBy field):
heimdall-job-68e65fff-d53f-408d-a8b4-5a429b3c5e14-0
heimdall-job-68e65fff-d53f-408d-a8b4-5a429b3c5e14-1
heimdall-job-68e65fff-d53f-408d-a8b4-5a429b3c5e14-2

This makes it so we don't need to find the old jobContext anywhere using the jobID.

I tested this locally and ensured both cancelation and stale job cleanup worked. In both cases, all jobs were canceled.

}

// Stop all tasks where LastStatus != STOPPED or SUCCEEDED
for _, task := range describeOutput.Tasks {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary. The API will not fail if you try to stop an already-stopped task.

// Log error but continue stopping other tasks
cleanupMethod.LogAndCountError(err, fmt.Sprintf("failed to stop task %s", aws.ToString(task.TaskArn)))
continue
cleanupMethod.LogAndCountError(err, fmt.Sprintf("failed to stop task %s", taskARN))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors wrapf?

for taskNum := 0; taskNum < e.TaskCount; taskNum++ {
maxTaskCount := clusterContext.MaxTaskCount

taskARNs := make(map[string]struct{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use list

hladush
hladush previously approved these changes Feb 19, 2026
@wlggraham wlggraham merged commit 360cb2a into main Feb 20, 2026
7 checks passed
@wlggraham wlggraham deleted the ecs_plugin_cancel_jobs_fix branch February 20, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants