Source code for flux_restful.library.launcher

import shlex
import subprocess

from flux_restful.core.config import settings
from flux_restful.library.env import build_helper_environment


[docs]def launch(kwargs, workdir=None, envars=None, user=None): """ Launch a job with a known launcher """ # TODO handle user case envars = envars or {} # Generate the flux job command = kwargs["command"] if isinstance(command, str): command = shlex.split(command) print(f"⭐️ Command being submit: {command}") # We don't allow commands willy nilly if command[0] not in settings.known_launchers: return f"{command[0]} is not a known launcher. " # Delete command from the kwargs (we added because is required and validated that way) del kwargs["command"] # Allowlisted server environment plus the user's envars. The launcher runs # on the server, outside any job shell, and submits jobs itself, so it # also needs FLUX_URI to reach this instance. environment = build_helper_environment(envars) print(f"⭐️ Workdir provided: {workdir}") # Submit using subprocess (we can see output in terminal, if any) try: subprocess.Popen( command, cwd=workdir, env=environment, stdout=None, stderr=None, stdin=None ) except Exception as e: return str(e) return "Job submit, see jobs table for spawned jobs."