Skip to content

Commit ab1e33b

Browse files
committed
move docker timestamp-parsing quirk to docker itself
our Container API can be more sensible and symmetrical than docker itself
1 parent 6966847 commit ab1e33b

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

repo2docker/app.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from urllib.parse import urlparse
2020

2121
import escapism
22-
from iso8601 import parse_date
2322
from pythonjsonlogger import jsonlogger
2423

2524
from traitlets import Any, Dict, Int, List, Unicode, Bool, default
@@ -650,13 +649,6 @@ def wait_for_container(self, container):
650649
"Container finished running.\n".upper(), extra=dict(phase="running")
651650
)
652651
# are there more logs? Let's send them back too
653-
if last_timestamp:
654-
# docker only accepts integer timestamps
655-
# this means we will usually replay logs from the last second
656-
# of the container
657-
# we should check if this ever returns anything new,
658-
# since we know it ~always returns something redundant
659-
last_timestamp = int(parse_date(last_timestamp).timestamp())
660652
late_logs = container.logs(since=last_timestamp).decode("utf-8")
661653
for line in late_logs.split("\n"):
662654
self.log.debug(line + "\n", extra=dict(phase="running"))

repo2docker/docker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44

55
import docker
6+
from iso8601 import parse_date
7+
68
from .engine import Container, ContainerEngine, ContainerEngineException, Image
79

810

@@ -14,6 +16,13 @@ def reload(self):
1416
return self._c.reload()
1517

1618
def logs(self, *, stream=False, timestamps=False, since=None):
19+
if since:
20+
# docker only accepts integer timestamps
21+
# this means we will usually replay logs from the last second
22+
# of the container
23+
# we should check if this ever returns anything new,
24+
# since we know it ~always returns something redundant
25+
since = int(parse_date(since).timestamp())
1726
return self._c.logs(stream=stream, timestamps=timestamps, since=since)
1827

1928
def kill(self, *, signal="KILL"):

repo2docker/engine.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def logs(self, *, stream=False, timestamps=False, since=None):
3131
If `True` return an iterator over the log lines, otherwise return all logs
3232
timestamps : bool
3333
If `True` log lines will be prefixed with iso8601 timestamps followed by space
34-
since : int
35-
An integer timestamp.
36-
Can be constructed by parsing timestamps in prefixed lines issued when `timestamps=True`.
34+
since : str
35+
A timestamp string
36+
Should be in the same format as the timestamp prefix given
37+
when `timestamps=True`
38+
3739
If given, start logs from this point,
3840
instead of from container start.
3941

0 commit comments

Comments
 (0)