Skip to content

Commit

Permalink
Finetune automatic log printing of failed batch jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 12, 2022
1 parent b73cc33 commit e67fb72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Setting the environment variable `OPENEO_BASEMAP_URL` allows to set a new templated URL to a XYZ basemap for the Vue Components library, `OPENEO_BASEMAP_ATTRIBUTION` allows to set the attribution for the basemap ([#260](https://github.com/Open-EO/openeo-python-client/issues/260))
- Initial support for experimental "federation:missing" flag on partial openEO Platform user job listings ([Open-EO/openeo-api#419](https://github.com/Open-EO/openeo-api/pull/419))
- Best effort detection of mistakenly using Python builtin `sum` or `all` functions in callbacks ([Forum #113](https://discuss.eodc.eu/t/reducing-masks-in-openeo/113))
- Automatically print batch job logs when job doesn't finish successfully (using `execute_batch/run_synchronous/start_and_wait`).


### Changed
Expand Down
10 changes: 8 additions & 2 deletions openeo/rest/job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import logging
import textwrap
import time
import typing
from pathlib import Path
Expand Down Expand Up @@ -204,10 +205,15 @@ def soft_error(message: str):
poll_interval = min(1.25 * poll_interval, max_poll_interval)

if status != "finished":
print("Your batch job failed. Logs can be found online in an openEO editor, or you can get them with 'connection.job('my_job_id_123').logs()'")
print(textwrap.dedent("""
Your batch job {i!r} failed.
Logs can be inspected in an openEO (web) editor or with `connection.job({i!r}).logs()`.
""".format(i=self.job_id)))
# TODO: make it possible to disable printing logs automatically?
# TODO: render logs jupyter-aware in a notebook context?
print("Printing logs:")
print(self.logs())
raise JobFailedException("Batch job {i} didn't finish properly. Status: {s} (after {t}).".format(
raise JobFailedException("Batch job {i!r} didn't finish successfully. Status: {s} (after {t}).".format(
i=self.job_id, s=status, t=elapsed()
), job=self)

Expand Down

0 comments on commit e67fb72

Please sign in to comment.