Skip to content

Commit

Permalink
Add check for existing output files during validation (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
nweires authored Feb 6, 2024
1 parent 75c951e commit bcc584c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions buildstockbatch/gcp/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,18 @@ def validate_gcp_args(project_file):

# Check that GCP bucket exists
bucket = cfg["gcp"]["gcs"]["bucket"]
output_dir = os.path.join(cfg["gcp"]["gcs"]["prefix"], "results", "simulation_output")
storage_client = storage.Client(project=gcp_project)
assert storage_client.bucket(bucket).exists(), f"GCS bucket {bucket} does not exist in project {gcp_project}"

blobs = storage_client.bucket(bucket).list_blobs(prefix=os.path.join(output_dir, "results_job"))
for blob in blobs:
raise ValidationError(
f"Output files are already present in bucket {bucket}! For example, {blob.name} exists. "
"Remove these files or chose a different file prefix. "
f"https://console.cloud.google.com/storage/browser/{bucket}/{output_dir}"
)

# Check that artifact registry repository exists
repo = cfg["gcp"]["artifact_registry"]["repository"]
ar_client = artifactregistry_v1.ArtifactRegistryClient()
Expand Down

0 comments on commit bcc584c

Please sign in to comment.