Skip to content

Instantly share code, notes, and snippets.

@varontron
Created July 21, 2022 22:16
Show Gist options
  • Save varontron/b33d0bd20206ec7bac1e51eaa964213e to your computer and use it in GitHub Desktop.
Save varontron/b33d0bd20206ec7bac1e51eaa964213e to your computer and use it in GitHub Desktop.
#!/bin/zsh
# The script will iterate through the queues and terminate any jobs in these queues with any of the following states:
# SUBMITTED PENDING RUNNABLE STARTING RUNNING
# Requirements:
# valid ~/.aws/credentials
# aws cli installed
# Usage:
# pass space-delimited quoted string of queue names as argument to script, e.g.,
# terminateJobs.zsh "my-nextflow-head-queue my-nextflow-small-process-queue my-nf-large-process-queue"
#
queues=($1)
for queue in ${=queues}
do
for state in SUBMITTED PENDING RUNNABLE STARTING RUNNING
do
for job in $(aws batch list-jobs --job-queue $queue --job-status $state --output text --query 'jobSummaryList[*].[jobId]')
do
echo -ne "Stopping job $job in state $state\t"
aws batch terminate-job --reason "Terminating job." --job-id $job && echo "Done." || echo "Failed."
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment