-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdelete_batch_job_queue.py
36 lines (29 loc) · 1.2 KB
/
delete_batch_job_queue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from time import sleep
import boto3
from botocore.exceptions import ClientError
AWS_BATCH_QUEUE_ALL_NAMES = os.environ["REFINEBIO_JOB_QUEUE_ALL_NAMES"].split(",")
batch = boto3.client("batch", region_name=os.environ["AWS_REGION"])
# First disable each job queue.
for batch_queue_name in AWS_BATCH_QUEUE_ALL_NAMES:
try:
batch.update_job_queue(jobQueue=batch_queue_name, state="DISABLED")
except ClientError as e:
# If the job queue doesn't exist, that's cool, we were trying to delete it anyway.
if str(e).endswith(" does not exist."):
pass
else:
raise e
# Then wait for each one to be disabled so it can be deleted.
for batch_queue_name in AWS_BATCH_QUEUE_ALL_NAMES:
while True:
job_queues = batch.describe_job_queues(jobQueues=[batch_queue_name])
if "jobQueues" in job_queues:
job_queue = job_queues["jobQueues"][0]
if job_queue["state"] == "DISABLED" and job_queue["status"] != "UPDATING":
break
else:
print(f"Unexpected response while describing job queue {batch_queue_name}.")
break
sleep(3)
batch.delete_job_queue(jobQueue=batch_queue_name)