7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-06-02 14:20:47 +00:00
tutor/tutor/jobs.py

43 lines
1.3 KiB
Python
Raw Normal View History

from tutor import env
from tutor.types import Config
class BaseJobRunner:
"""
A job runner is responsible for running bash commands in the right context.
Commands may be loaded from string or template files. The `run_job` method must be
implemented by child classes.
"""
def __init__(self, root: str, config: Config):
self.root = root
self.config = config
def run_job_from_template(self, service: str, *path: str) -> None:
2019-06-05 17:57:30 +00:00
command = self.render(*path)
self.run_job(service, command)
def run_job_from_str(self, service: str, command: str) -> None:
rendered = env.render_str(self.config, command).strip()
self.run_job(service, rendered)
def render(self, *path: str) -> str:
rendered = env.render_file(self.config, *path).strip()
if isinstance(rendered, bytes):
raise TypeError("Cannot load job from binary file")
return rendered
2019-06-05 17:57:30 +00:00
def run_job(self, service: str, command: str) -> int:
"""
Given a (potentially large) string command, run it with the
corresponding service. Implementations will differ depending on the
deployment strategy.
"""
raise NotImplementedError
class BaseComposeJobRunner(BaseJobRunner):
def docker_compose(self, *command: str) -> int:
raise NotImplementedError