def _run_command(ctx): """Execute a shell command and capture its output and exit status.""" if cylc.flags.debug: if ctx.cmd_kwargs.get('shell'): OUT.debug(ctx.cmd) else: OUT.debug("%s\n" % ' '.join([quote(cmd_str) for cmd_str in ctx.cmd])) if (SuiteProcPool.STOP_JOB_SUBMISSION.value and ctx.cmd_key == SuiteProcPool.JOBS_SUBMIT): ctx.err = "job submission skipped (suite stopping)" ctx.ret_code = SuiteProcPool.JOB_SKIPPED_FLAG ctx.timestamp = get_current_time_string() return ctx try: stdin_file = None if ctx.cmd_kwargs.get('stdin_file_paths'): stdin_file = TemporaryFile() for file_path in ctx.cmd_kwargs['stdin_file_paths']: for line in open(file_path): stdin_file.write(line) stdin_file.seek(0) elif ctx.cmd_kwargs.get('stdin_str'): stdin_file = PIPE proc = Popen(ctx.cmd, stdin=stdin_file, stdout=PIPE, stderr=PIPE, env=ctx.cmd_kwargs.get('env'), shell=ctx.cmd_kwargs.get('shell')) except IOError as exc: if cylc.flags.debug: traceback.print_exc() ctx.ret_code = 1 ctx.err = str(exc) except OSError as exc: if exc.filename is None: exc.filename = ctx.cmd[0] if cylc.flags.debug: traceback.print_exc() ctx.ret_code = 1 ctx.err = str(exc) else: ctx.out, ctx.err = proc.communicate(ctx.cmd_kwargs.get('stdin_str')) ctx.ret_code = proc.wait() ctx.timestamp = get_current_time_string() return ctx
def _run_command(ctx): """Execute a shell command and capture its output and exit status.""" if cylc.flags.debug: if ctx.cmd_kwargs.get('shell'): OUT.debug(ctx.cmd) else: OUT.debug( "%s\n" % ' '.join([quote(cmd_str) for cmd_str in ctx.cmd])) if (SuiteProcPool.STOP_JOB_SUBMISSION.value and ctx.cmd_key == SuiteProcPool.JOBS_SUBMIT): ctx.err = "job submission skipped (suite stopping)" ctx.ret_code = SuiteProcPool.JOB_SKIPPED_FLAG ctx.timestamp = get_current_time_string() return ctx try: stdin_file = None if ctx.cmd_kwargs.get('stdin_file_paths'): stdin_file = TemporaryFile() for file_path in ctx.cmd_kwargs['stdin_file_paths']: for line in open(file_path): stdin_file.write(line) stdin_file.seek(0) elif ctx.cmd_kwargs.get('stdin_str'): stdin_file = PIPE proc = Popen( ctx.cmd, stdin=stdin_file, stdout=PIPE, stderr=PIPE, env=ctx.cmd_kwargs.get('env'), shell=ctx.cmd_kwargs.get('shell')) except IOError as exc: if cylc.flags.debug: traceback.print_exc() ctx.ret_code = 1 ctx.err = str(exc) except OSError as exc: if exc.filename is None: exc.filename = ctx.cmd[0] if cylc.flags.debug: traceback.print_exc() ctx.ret_code = 1 ctx.err = str(exc) else: ctx.out, ctx.err = proc.communicate(ctx.cmd_kwargs.get('stdin_str')) ctx.ret_code = proc.wait() ctx.timestamp = get_current_time_string() return ctx
def send_retry(self, event_message, event_id, max_n_tries, retry_intvl_secs): """CLI external trigger interface.""" max_n_tries = int(max_n_tries or self.__class__.MAX_N_TRIES) retry_intvl_secs = float(retry_intvl_secs or self.__class__.RETRY_INTVL_SECS) sent = False i_try = 0 while not sent and i_try < max_n_tries: i_try += 1 try: self.put(event_message, event_id) except Exception as exc: ERR.error(exc) OUT.info(self.__class__.MSG_SEND_FAILED % ( i_try, max_n_tries, )) if i_try >= max_n_tries: break OUT.info(self.__class__.MSG_SEND_RETRY % (retry_intvl_secs, self.timeout)) sleep(retry_intvl_secs) else: if i_try > 1: OUT.info(self.__class__.MSG_SEND_SUCCEEDED % (i_try, max_n_tries)) sent = True break if not sent: sys.exit('ERROR: send failed') return sent
def load_db_broadcast_states(self, row_idx, row): """Load broadcast variables from runtime DB broadcast states row.""" if row_idx == 0: OUT.info("LOADING broadcast states") point, namespace, key, value = row sections = [] cur_key = key if "]" in cur_key: sections = self.REC_SECTION.findall(cur_key) cur_key = cur_key.rsplit(r"]", 1)[-1] with self.lock: self.settings.setdefault(point, {}) self.settings[point].setdefault(namespace, {}) dict_ = self.settings[point][namespace] for section in sections: dict_.setdefault(section, {}) dict_ = dict_[section] dict_[cur_key] = value OUT.info(CHANGE_FMT.strip() % { "change": CHANGE_PREFIX_SET, "point": point, "namespace": namespace, "key": key, "value": value})
def send_retry(self, event_message, event_id, max_n_tries, retry_intvl_secs): """CLI external trigger interface.""" max_n_tries = int(max_n_tries or self.__class__.MAX_N_TRIES) retry_intvl_secs = float( retry_intvl_secs or self.__class__.RETRY_INTVL_SECS) sent = False i_try = 0 while not sent and i_try < max_n_tries: i_try += 1 try: self.put(event_message, event_id) except Exception as exc: ERR.error(exc) OUT.info(self.__class__.MSG_SEND_FAILED % ( i_try, max_n_tries, )) if i_try >= max_n_tries: break OUT.info(self.__class__.MSG_SEND_RETRY % ( retry_intvl_secs, self.timeout )) sleep(retry_intvl_secs) else: if i_try > 1: OUT.info(self.__class__.MSG_SEND_SUCCEEDED % ( i_try, max_n_tries )) sent = True break if not sent: sys.exit('ERROR: send failed') return sent
def load_xtrigger_for_restart(self, row_idx, row): """Load satisfied xtrigger results from suite DB.""" if row_idx == 0: OUT.info("LOADING satisfied xtriggers") sig, results = row self.sat_xtrig[sig] = json.loads(results)
def dump(self): # for debugging log_msg = "BROKER DUMP:" for msg in self.all_outputs: log_msg += "\n+ " + self.all_outputs[msg] + '\t' + msg OUT.info(log_msg)