Skip to content

Instantly share code, notes, and snippets.

@atemate
Created December 22, 2021 10:48
Show Gist options
  • Save atemate/1cba785c101732f74954078041e151b1 to your computer and use it in GitHub Desktop.
Save atemate/1cba785c101732f74954078041e151b1 to your computer and use it in GitHub Desktop.
Delete all my Vertex jobs
import yaml
# gcloud ai custom-jobs list --region=us-central1 > /tmp/jobs.txt
path = '/tmp/jobs.txt'
PROJECT_ID = "..."
subname = 'artem'
with open(path) as f:
data = list(yaml.load_all(f, Loader=yaml.FullLoader))
print(len(data))
# Filter by name:
d = [x for x in data if subname in x['displayName']]
print(len(d))
ids = [x['name'].split('/')[-1] for x in d]
print(ids)
# delete jobs, https://cloud.google.com/vertex-ai/docs/samples/aiplatform-delete-custom-job-sample
from google.cloud import aiplatform
def delete_custom_job_sample(
project: str,
custom_job_id: str,
location: str = "us-central1",
api_endpoint: str = "us-central1-aiplatform.googleapis.com",
timeout: int = 300,
):
# The AI Platform services require regional API endpoints.
client_options = {"api_endpoint": api_endpoint}
# Initialize client that will be used to create and send requests.
# This client only needs to be created once, and can be reused for multiple requests.
client = aiplatform.gapic.JobServiceClient(client_options=client_options)
name = client.custom_job_path(
project=project, location=location, custom_job=custom_job_id
)
response = client.delete_custom_job(name=name)
print("Long running operation:", response.operation.name)
delete_custom_job_response = response.result(timeout=timeout)
print("delete_custom_job_response:", delete_custom_job_response)
for x in ids:
print(x)
delete_custom_job_sample(PROJECT_ID, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment