Skip to content

Instantly share code, notes, and snippets.

@djm
Last active August 31, 2015 21:02
Show Gist options
  • Select an option

  • Save djm/404de9d2dd25e93aee6f to your computer and use it in GitHub Desktop.

Select an option

Save djm/404de9d2dd25e93aee6f to your computer and use it in GitHub Desktop.
Delete/cancel all in progress and pending jobs in an Elastic Transcoder region
import time
from boto import elastictranscoder
REQUEST_FREQ = 0.3 # Every x seconds
REGION = 'eu-west-1'
TO_CANCEL = [
'Progressing',
'Submitted'
]
def main():
et = elastictranscoder.connect_to_region(REGION)
all_jobs = []
for status in TO_CANCEL:
jobs = get_jobs(et, status)
all_jobs.extend(jobs)
cancel_jobs(et, all_jobs)
def get_jobs(et, status, jobs=None, page_token=None):
print("Get jobs: status => {}, page token => {}".format(status, page_token))
if jobs is None:
jobs = []
time.sleep(REQUEST_FREQ)
response = et.list_jobs_by_status(status, page_token=page_token)
jobs.extend(response['Jobs'])
page_token = response['NextPageToken']
if page_token:
return get_jobs(et, status, jobs=jobs, page_token=page_token)
return jobs
def cancel_jobs(et, jobs):
for job in jobs:
job_id = job['Id']
print("Cancelling Job ID: {}".format(job_id))
et.cancel_job(job_id)
time.sleep(REQUEST_FREQ)
if __name__ == '__main__':
main()
@djm

djm commented Aug 31, 2015

Copy link
Copy Markdown
Author

This bog simple run-once script was written as the AWS Console does not support deleting all progressing/pending jobs. It uses incredibly dumb request limiting in the form of time.sleep. As it was written for me, some variables are hardcoded but they could easily be read from the command line with a few modifications.

Usage:

  1. Set the REGION variable to your region.

  2. Run with:

AWS_ACCESS_KEY_ID=<...> AWS_SECRET_ACCESS_KEY=<...> python cancel_jobs.py

Requires:

Python 2.7/Python 3.2+
boto==2.28.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment