def submit(self): self._create_logdir() self._remove_previous_logs() try: external_job_id = self._submit_cmd_and_get_external_job_id() parameters_to_status_script = self._get_parameters_to_status_script( external_job_id) OSLayer.print(parameters_to_status_script) except subprocess.CalledProcessError as error: raise BsubInvocationError(error) except AttributeError as error: raise JobidNotFoundError(error)
def _query_status_using_bjobs(self) -> str: output_stream, error_stream = OSLayer.run_process(self.bjobs_query_cmd) stdout_is_empty = not output_stream.strip() if stdout_is_empty: raise BjobsError( "bjobs error.\nstdout is empty.\nstderr = {stderr}".format( stderr=error_stream ) ) return self.STATUS_TABLE[output_stream]
def __init__( self, jobscript: PathLike, cluster_cmds: List[str] = None, memory_units: Unit = Unit.MEGA, lsf_config: Optional[Config] = None, ): if cluster_cmds is None: cluster_cmds = [] if lsf_config is None: lsf_config = Config() self._jobscript = jobscript self._cluster_cmd = " ".join(cluster_cmds) self._job_properties = read_job_properties(self._jobscript) self.random_string = OSLayer.get_uuid4_string() self._memory_units = memory_units self.lsf_config = lsf_config
def _query_status_using_bjobs(self) -> str: output_stream, error_stream = OSLayer.run_process(self.bjobs_query_cmd) stdout_is_empty = not output_stream.strip() if stdout_is_empty: raise BjobsError( "bjobs error.\nstdout is empty.\nstderr = {stderr}".format( stderr=error_stream ) ) if output_stream == UNKNOWN: return self._handle_unknown_job() if output_stream == ZOMBIE: return self._handle_zombie_job() return self.STATUS_TABLE[output_stream]
def _kill_job(self): kill_cmd = "bkill -r {}".format(self.jobid) _ = OSLayer.run_process(kill_cmd)
def _get_tail_of_log_file(self) -> List[str]: # 30 lines gives us the whole LSF completion summary tail = OSLayer.tail(self.outlog, num_lines=30) return [line.decode().strip() for line in tail]
def _submit_cmd_and_get_external_job_id(self) -> int: output_stream, error_stream = OSLayer.run_process(self.submit_cmd) match = re.search(r"Job <(\d+)> is submitted", output_stream) jobid = match.group(1) return int(jobid)
def _remove_previous_logs(self): OSLayer.remove_file(self.outlog) OSLayer.remove_file(self.errlog)
def _create_logdir(self): OSLayer.mkdir(self.logdir)