Exemplo n.º 1
0
    def run_job(self, client: Client, job: Any, run_path: Path):
        shell_cmd = [
            job.get_executable().as_posix(),
            *[os.path.expandvars(arg) for arg in job.get_args()],
        ]
        env = os.environ.copy()
        env.update({
            "PATH":
            (run_path / _BIN_FOLDER).as_posix() + ":" + os.environ["PATH"]
        })
        cmd_exec = subprocess.run(
            shell_cmd,
            universal_newlines=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=run_path.as_posix(),
            env=env,
        )
        self.logger.info(cmd_exec.stderr)
        self.logger.info(cmd_exec.stdout)

        if cmd_exec.returncode != 0:
            self.logger.error(cmd_exec.stderr)
            client.send_event(
                ev_type=ids.EVTYPE_FM_JOB_FAILURE,
                ev_source=job.get_source(self._ee_id),
                ev_data={ids.ERROR_MSG: cmd_exec.stderr},
            )
            raise OSError(
                f"Script {job.get_name()} failed with exception {cmd_exec.stderr}"
            )
Exemplo n.º 2
0
 def run_jobs(self, client: Client, run_path: Path):
     for job in self._step.get_jobs():
         self.logger.info(f"Running command {job.get_name()}")
         client.send_event(
             ev_type=ids.EVTYPE_FM_JOB_START,
             ev_source=job.get_source(self._ee_id),
         )
         self.run_job(client, job, run_path)
         client.send_event(
             ev_type=ids.EVTYPE_FM_JOB_SUCCESS,
             ev_source=job.get_source(self._ee_id),
         )
Exemplo n.º 3
0
 def run_job(
     self,
     job: _FunctionJob,
     transmitters: _stage_transmitter_mapping,
     client: Client,
 ) -> _stage_transmitter_mapping:
     self.logger.info(f"Running function {job.name}")
     client.send_event(
         ev_type=ids.EVTYPE_FM_JOB_START,
         ev_source=job.source(self._ee_id),
     )
     try:
         function: Callable[..., Any] = pickle.loads(job.command)
         output = self._attempt_execute(func=function, transmitters=transmitters)
     except Exception as e:
         self.logger.error(str(e))
         client.send_event(
             ev_type=ids.EVTYPE_FM_JOB_FAILURE,
             ev_source=job.source(self._ee_id),
             ev_data={ids.ERROR_MSG: str(e)},
         )
         raise e
     else:
         client.send_event(
             ev_type=ids.EVTYPE_FM_JOB_SUCCESS,
             ev_source=job.source(self._ee_id),
         )
     return output