move docker timestamp-parsing quirk to docker itself

our Container API can be more sensible and symmetrical than docker itself
pull/1016/head
Min RK 2021-07-09 10:24:09 +02:00
rodzic 6966847bf9
commit ab1e33bc4c
3 zmienionych plików z 14 dodań i 11 usunięć

Wyświetl plik

@ -19,7 +19,6 @@ import time
from urllib.parse import urlparse
import escapism
from iso8601 import parse_date
from pythonjsonlogger import jsonlogger
from traitlets import Any, Dict, Int, List, Unicode, Bool, default
@ -650,13 +649,6 @@ class Repo2Docker(Application):
"Container finished running.\n".upper(), extra=dict(phase="running")
)
# are there more logs? Let's send them back too
if last_timestamp:
# docker only accepts integer timestamps
# this means we will usually replay logs from the last second
# of the container
# we should check if this ever returns anything new,
# since we know it ~always returns something redundant
last_timestamp = int(parse_date(last_timestamp).timestamp())
late_logs = container.logs(since=last_timestamp).decode("utf-8")
for line in late_logs.split("\n"):
self.log.debug(line + "\n", extra=dict(phase="running"))

Wyświetl plik

@ -3,6 +3,8 @@ Docker container engine for repo2docker
"""
import docker
from iso8601 import parse_date
from .engine import Container, ContainerEngine, ContainerEngineException, Image
@ -14,6 +16,13 @@ class DockerContainer(Container):
return self._c.reload()
def logs(self, *, stream=False, timestamps=False, since=None):
if since:
# docker only accepts integer timestamps
# this means we will usually replay logs from the last second
# of the container
# we should check if this ever returns anything new,
# since we know it ~always returns something redundant
since = int(parse_date(since).timestamp())
return self._c.logs(stream=stream, timestamps=timestamps, since=since)
def kill(self, *, signal="KILL"):

Wyświetl plik

@ -31,9 +31,11 @@ class Container(ABC):
If `True` return an iterator over the log lines, otherwise return all logs
timestamps : bool
If `True` log lines will be prefixed with iso8601 timestamps followed by space
since : int
An integer timestamp.
Can be constructed by parsing timestamps in prefixed lines issued when `timestamps=True`.
since : str
A timestamp string
Should be in the same format as the timestamp prefix given
when `timestamps=True`
If given, start logs from this point,
instead of from container start.