Skip to content

Commit 2393a3d

Browse files
authored
fix health (#170)
1 parent 8397531 commit 2393a3d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

data-collection/deploy/module-health-events.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,13 @@ Resources:
196196
end_date = datetime.now(timezone.utc)
197197
start_date = end_date - timedelta(days=LOOKBACK)
198198
# Check the create time of objects in the S3 bucket
199-
paginator = boto3.client('s3').get_paginator('list_objects_v2')
200-
contents = sum( [page.get('Contents', []) for page in paginator.paginate(Bucket=bucket, Prefix=s3_path)], [])
201-
last_file_date = get_last_modified_date(contents)
202-
if last_file_date and last_file_date >= start_date:
203-
start_date = last_file_date
199+
contents = boto3.client('s3').get_paginator('list_objects_v2').paginate(
200+
Bucket=bucket,
201+
Prefix=s3_path
202+
).search('Contents')
203+
start_date = max([obj['LastModified'] for obj in contents if obj] + [start_date])
204204
return start_date, end_date
205205
206-
def get_last_modified_date(contents):
207-
""" Helper for calculate_dates """
208-
last_modified_dates = [obj['LastModified'] for obj in contents]
209-
last_modified_dates_within_90_days = [datetime for datetime in last_modified_dates if datetime >= datetime.now(timezone.utc) - timedelta(days=90)]
210-
if last_modified_dates_within_90_days:
211-
return max(last_modified_dates_within_90_days)
212-
return None
213206
214207
def search(function, args=None, expression='@'):
215208
compiled = jmespath.compile(expression)

0 commit comments

Comments
 (0)