Skip to content

Commit

Permalink
runner.aws_batch: Gracefully handle errors when fetching logs for com…
Browse files Browse the repository at this point in the history
…pleted jobs

For completed jobs, it's more useful to continue on with printing the
job status (e.g. success or reason for failure) and downloading job
results even if an error occurs when fetching logs.  As a concrete
example, we've observed cases where a failed job has a log stream
associated with it in Batch but that log stream does not actually exist
in CloudWatch Logs.¹  The log fetch error hid the reason for job
failure, hampering troubleshooting.

¹ <https://bedfordlab.slack.com/archives/C01LCTT7JNN/p1730406138009409>
  • Loading branch information
tsibley committed Oct 31, 2024
1 parent 8cf025d commit a9b9d3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ development source code and as such may not be routinely kept up to date.

# __NEXT__

## Bug fixes

* It is no longer a fatal error if the logs for a completed AWS Batch job
cannot be fetched for some reason. `nextstrain build` will warn about the
error but continue on with printing the job status (e.g. success or reason
for failure) and, if applicable, downloading job results.
([#406](https://github.com/nextstrain/cli/pull/406))


# 8.5.3 (3 September 2024)

Expand Down
8 changes: 6 additions & 2 deletions nextstrain/cli/runner/aws_batch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
Default for ``--aws-batch-memory``.
"""

import botocore.exceptions
import os
import shlex
from datetime import datetime
Expand Down Expand Up @@ -404,8 +405,11 @@ def interrupt_signaled(sig, frame):
# The watcher never started, so we probably missed the
# transition to running. Display the whole log now!
if opts.logs:
for entry in job.log_entries():
print_job_log(entry)
try:
for entry in job.log_entries():
print_job_log(entry)
except botocore.exceptions.ClientError as error:
warn(f"Unable to fetch job logs: {error}")

print_stage(
"Job %s after %0.1f minutes" % (job.status, job.elapsed_time / 60),
Expand Down

0 comments on commit a9b9d3e

Please sign in to comment.