kopia lustrzana https://github.com/jupyterhub/repo2docker
move docker timestamp-parsing quirk to docker itself
our Container API can be more sensible and symmetrical than docker itselfpull/1016/head
rodzic
6966847bf9
commit
ab1e33bc4c
|
@ -19,7 +19,6 @@ import time
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import escapism
|
import escapism
|
||||||
from iso8601 import parse_date
|
|
||||||
from pythonjsonlogger import jsonlogger
|
from pythonjsonlogger import jsonlogger
|
||||||
|
|
||||||
from traitlets import Any, Dict, Int, List, Unicode, Bool, default
|
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")
|
"Container finished running.\n".upper(), extra=dict(phase="running")
|
||||||
)
|
)
|
||||||
# are there more logs? Let's send them back too
|
# 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")
|
late_logs = container.logs(since=last_timestamp).decode("utf-8")
|
||||||
for line in late_logs.split("\n"):
|
for line in late_logs.split("\n"):
|
||||||
self.log.debug(line + "\n", extra=dict(phase="running"))
|
self.log.debug(line + "\n", extra=dict(phase="running"))
|
||||||
|
|
|
@ -3,6 +3,8 @@ Docker container engine for repo2docker
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
from iso8601 import parse_date
|
||||||
|
|
||||||
from .engine import Container, ContainerEngine, ContainerEngineException, Image
|
from .engine import Container, ContainerEngine, ContainerEngineException, Image
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +16,13 @@ class DockerContainer(Container):
|
||||||
return self._c.reload()
|
return self._c.reload()
|
||||||
|
|
||||||
def logs(self, *, stream=False, timestamps=False, since=None):
|
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)
|
return self._c.logs(stream=stream, timestamps=timestamps, since=since)
|
||||||
|
|
||||||
def kill(self, *, signal="KILL"):
|
def kill(self, *, signal="KILL"):
|
||||||
|
|
|
@ -31,9 +31,11 @@ class Container(ABC):
|
||||||
If `True` return an iterator over the log lines, otherwise return all logs
|
If `True` return an iterator over the log lines, otherwise return all logs
|
||||||
timestamps : bool
|
timestamps : bool
|
||||||
If `True` log lines will be prefixed with iso8601 timestamps followed by space
|
If `True` log lines will be prefixed with iso8601 timestamps followed by space
|
||||||
since : int
|
since : str
|
||||||
An integer timestamp.
|
A timestamp string
|
||||||
Can be constructed by parsing timestamps in prefixed lines issued when `timestamps=True`.
|
Should be in the same format as the timestamp prefix given
|
||||||
|
when `timestamps=True`
|
||||||
|
|
||||||
If given, start logs from this point,
|
If given, start logs from this point,
|
||||||
instead of from container start.
|
instead of from container start.
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue