Last active
August 31, 2015 21:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Set the
REGIONvariable to your region.Run with:
Requires: