Skip to content

Commit

Permalink
better handling of get_log_events pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
markjschreiber committed Sep 17, 2024
1 parent 2a2d090 commit d1dc7bf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions omics/cli/run_analyzer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def stream_to_run(strm):
def get_streams(logs, rqst, start_time=None):
"""Get matching CloudWatch Log streams"""
streams = []
# using boto3 get the log stream descriptions for the request, paginating the responses
for page in logs.get_paginator("describe_log_streams").paginate(**rqst):
done = False
for strm in page["logStreams"]:
Expand Down Expand Up @@ -223,14 +224,12 @@ def get_run_resources(logs, run):
resources = []
done = False
while not done:
resp = logs.get_log_events(**rqst)
for evt in resp.get("events", []):
try:
resources.append(json.loads(evt["message"]))
except Exception:
pass
if evt["timestamp"] >= run["lastEventTimestamp"]:
done = True
resp = logs.get_log_events(**rqst, limit=1024)
events = resp.get("events", [])
if not events:
done = True
for evt in resp.get("events"):
resources.append(json.loads(evt["message"]))
token = resp.get("nextForwardToken")
if not token or token == rqst.get("nextToken"):
done = True
Expand Down

0 comments on commit d1dc7bf

Please sign in to comment.