Skip to content

Commit

Permalink
Add since arg to Beaker.job.follow
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed May 31, 2024
1 parent 699fa36 commit 8d0ea26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use patch releases for compatibility fixes instead.

## Unreleased

### Added

- Added `since` argument to `Beaker.job.follow`.

## [v1.26.15](https://github.com/allenai/beaker-py/releases/tag/v1.26.15) - 2024-05-30

### Fixed
Expand Down
9 changes: 7 additions & 2 deletions beaker/services/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def follow(
timeout: Optional[float] = None,
strict: bool = False,
include_timestamps: bool = True,
since: Optional[Union[str, datetime, timedelta]] = None,
) -> Generator[bytes, None, Job]:
"""
Follow a job live, creating a generator that produces log lines (as bytes) from the job
Expand All @@ -419,6 +420,10 @@ def follow(
:class:`~beaker.exceptions.JobFailedError` will be raised for non-zero exit codes.
:param include_timestamps: If ``True`` (the default) timestamps from the Beaker logs
will be included in the output.
:param since: Only show logs since a particular time. Could be a :class:`~datetime.datetime` object
(naive datetimes will be treated as UTC), a timestamp string in the form of RFC 3339
(e.g. "2013-01-02T13:23:37Z"), or a relative time
(e.g. a :class:`~datetime.timedelta` or a string like "42m").
:raises JobNotFound: If any job can't be found.
:raises JobTimeoutError: If the ``timeout`` expires.
Expand All @@ -443,13 +448,13 @@ def follow(
...
"""
from ..util import log_and_wait, split_timestamp
from ..util import format_since, log_and_wait, split_timestamp

if timeout is not None and timeout <= 0:
raise ValueError("'timeout' must be a positive number")

start = time.monotonic()
last_timestamp: Optional[str] = None
last_timestamp: Optional[str] = None if since is None else format_since(since)
lines_for_timestamp: Dict[str, Set[bytes]] = defaultdict(set)

def get_line_to_yield(line: bytes) -> Optional[bytes]:
Expand Down

0 comments on commit 8d0ea26

Please sign in to comment.