Kill all the zombies π§ββοΈ #3780
This file contains 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
name: Kill all the zombies π§ββοΈ | |
on: | |
schedule: | |
- cron: '0 */2 * * *' | |
workflow_dispatch: | |
jobs: | |
kill-zombies: | |
name: I am here to chew gum, and kill stuck jobs, and I am all out of gum! | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
steps: | |
- name: Authenticate to Google Cloud | |
id: "auth" | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: "${{ secrets.GCP_DATAFLOW_SERVICE_KEY }}" | |
- name: Set up Cloud SDK and upload csv files | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Kill all active jobs older than 6 hours | |
shell: python -u {0} | |
run: | | |
import subprocess | |
import json | |
jobs = json.loads(subprocess.check_output([ | |
"gcloud", "dataflow", "jobs", "list", | |
"--created-before=-p6h", "--status=active", | |
"--filter=name:a618127503*", "--format=json", | |
"--region=us-central1" | |
])) | |
if jobs: | |
for job in jobs: | |
subprocess.check_call([ | |
"gcloud", "dataflow", "jobs", "cancel", | |
str(job["id"]), | |
"--region=us-central1" | |
]) | |
env: | |
GOOGLE_APPLICATION_CREDENTIALS: "${{ steps.auth.outputs.credentials_file_path }}" |