Skip to content

Commit

Permalink
Reuse s3 client for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
conbrad committed Jul 15, 2024
1 parent d67c0c9 commit d7f7bb2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/app/weather_models/precip_rdps_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ async def compute_and_store_precip_rasters(current_time: datetime):
Given a UTC datetime, trigger 24 hours worth of accumulated precip
difference rasters and store them.
"""
for hour in range(0, 24):
timestamp = current_time + timedelta(hours=hour)
(precip_diff_raster, geotransform, projection) = await generate_24_hour_accumulating_precip_raster(timestamp)
key = f"weather_models/{ModelEnum.RDPS.lower()}/{current_time.date().isoformat()}/" + compose_computed_precip_rdps_key(
current_time, current_time.hour, hour, SourcePrefix.COMPUTED
)
async with get_client() as (client, bucket):
async with get_client() as (client, bucket):
for hour in range(0, 24):
timestamp = current_time + timedelta(hours=hour)
(precip_diff_raster, geotransform, projection) = await generate_24_hour_accumulating_precip_raster(timestamp)
key = f"weather_models/{ModelEnum.RDPS.lower()}/{current_time.date().isoformat()}/" + compose_computed_precip_rdps_key(

Check warning on line 39 in api/app/weather_models/precip_rdps_model.py

View check run for this annotation

Codecov / codecov/patch

api/app/weather_models/precip_rdps_model.py#L35-L39

Added lines #L35 - L39 were not covered by tests
current_time, current_time.hour, hour, SourcePrefix.COMPUTED
)

res = await client.list_objects_v2(Bucket=bucket, Prefix=key, MaxKeys=1)
if "Contents" in res:
logger.info("File already exists for key: %s, skipping", key)
Expand Down

0 comments on commit d7f7bb2

Please sign in to comment.