mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
initial
This commit is contained in:
@@ -82,6 +82,33 @@ def list_s3_objects():
|
||||
)
|
||||
|
||||
|
||||
def cleanup_old_s3_objects():
|
||||
|
||||
bucket_name = current_app.config["CSV_UPLOAD_BUCKET"]["bucket"]
|
||||
s3_client = get_s3_client()
|
||||
# Our reports only support 7 days, but can be scheduled 3 days in advance
|
||||
# Use 14 day for the v1.0 version of this behavior
|
||||
time_limit = aware_utcnow() - datetime.timedelta(days=14)
|
||||
try:
|
||||
response = s3_client.list_objects_v2(Bucket=bucket_name)
|
||||
while True:
|
||||
for obj in response.get("Contents", []):
|
||||
if obj["LastModified"] >= time_limit:
|
||||
print(f"{obj['LastModified']} {obj['Key']}")
|
||||
if "NextContinuationToken" in response:
|
||||
response = s3_client.list_objects_v2(
|
||||
Bucket=bucket_name,
|
||||
ContinuationToken=response["NextContinuationToken"],
|
||||
)
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
current_app.logger.error(
|
||||
f"An error occurred while cleaning up old s3 objects #notify-api-1303",
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
|
||||
def get_s3_files():
|
||||
|
||||
bucket_name = current_app.config["CSV_UPLOAD_BUCKET"]["bucket"]
|
||||
|
||||
Reference in New Issue
Block a user