Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Environment wrapper for dumping output logs
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wierzbicki <awierzbicki@golem.network>
  • Loading branch information
Wiezzel committed Nov 7, 2019
1 parent 909a696 commit 6ff43ee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions golem/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CounterUsage = Any

EnvId = str
RuntimeId = str


class RuntimeEventType(Enum):
Expand Down Expand Up @@ -161,6 +162,12 @@ class Runtime(ABC):
""" A runnable object representing some particular computation. Tied to a
particular Environment that was used to create this object. """

@abstractmethod
def id(self) -> Optional[RuntimeId]:
""" Get unique identifier of this Runtime. Might not be available if the
Runtime is not yet prepared. """
raise NotImplementedError

@abstractmethod
def prepare(self) -> Deferred:
""" Prepare the Runtime to be started. Assumes current status is
Expand Down
4 changes: 4 additions & 0 deletions golem/envs/docker/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
EnvSupportStatus,
Prerequisites,
RuntimeBase,
RuntimeId,
RuntimeInput,
RuntimeOutput,
RuntimePayload,
Expand Down Expand Up @@ -231,6 +232,9 @@ def _update_status_loop(self) -> None:
self._logger.info("Runtime is no longer running. "
"Stopping status update thread.")

def id(self) -> Optional[RuntimeId]:
return self._container_id

def prepare(self) -> Deferred:
self._change_status(
from_status=RuntimeStatus.CREATED,
Expand Down
4 changes: 4 additions & 0 deletions golem/envs/wrappers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Runtime,
RuntimeEventListener,
RuntimeEventType,
RuntimeId,
RuntimeInput,
RuntimeOutput,
RuntimePayload,
Expand All @@ -34,6 +35,9 @@ class RuntimeWrapper(Runtime):
def __init__(self, runtime: Runtime) -> None:
self._runtime = runtime

def id(self) -> Optional[RuntimeId]:
return self._runtime.id()

def prepare(self) -> Deferred:
return self._runtime.prepare()

Expand Down
8 changes: 8 additions & 0 deletions tests/golem/envs/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import multiprocessing
import signal
import uuid
from pathlib import Path
from typing import Optional, Dict, Any, Tuple, List, Awaitable, Callable

Expand All @@ -24,6 +25,7 @@
Prerequisites,
Runtime,
RuntimeBase,
RuntimeId,
RuntimeInput,
RuntimeOutput,
RuntimePayload
Expand Down Expand Up @@ -72,6 +74,7 @@ class LocalhostPayload(RuntimePayload):
command: str
shared_dir: Path
prerequisites: LocalhostPrerequisites
runtime_id: Optional[RuntimeId]


class LocalhostPayloadBuilder(TaskApiPayloadBuilder):
Expand Down Expand Up @@ -150,6 +153,8 @@ def __init__(
payload: LocalhostPayload,
) -> None:
super().__init__(logger)
self._id = payload.runtime_id or str(uuid.uuid4())

# From docs: Start a fresh python interpreter process. Unnecessary
# file descriptors and handles from the parent process will not
# be inherited.
Expand All @@ -161,6 +166,9 @@ def __init__(
)
self._shutdown_deferred: Optional[defer.Deferred] = None

def id(self) -> Optional[RuntimeId]:
return self._id

def prepare(self) -> defer.Deferred:
self._prepared()
return defer.succeed(None)
Expand Down

0 comments on commit 6ff43ee

Please sign in to comment.