def execute(exec_async: bool = False): """ :param exec_async: Whether or not to allow asynchronous command execution that returns before the command is complete with a run_uid that can be used to track the continued execution of the command until completion. """ r = Response() r.update(server=server_runner.get_server_data()) cmd, args = parse_command_args(r) if r.failed: return flask.jsonify(r.serialize()) try: commander.execute(cmd, args, r) if not r.thread: return flask.jsonify(r.serialize()) if not exec_async: r.thread.join() server_runner.active_execution_responses[r.thread.uid] = r # Watch the thread for a bit to see if the command finishes in # that time. If it does the command result will be returned directly # to the caller. Otherwise, a waiting command will be issued count = 0 while count < 5: count += 1 r.thread.join(0.25) if not r.thread.is_alive(): break if r.thread.is_alive(): return flask.jsonify(Response().update( run_log=r.get_thread_log(), run_status='running', run_uid=r.thread.uid, step_changes=server_runner.get_running_step_changes(True), server=server_runner.get_server_data()).serialize()) del server_runner.active_execution_responses[r.thread.uid] r.update(run_log=r.get_thread_log(), run_status='complete', run_multiple_updates=False, run_uid=r.thread.uid) except Exception as err: r.fail(code='KERNEL_EXECUTION_FAILURE', message='Unable to execute command', cmd=cmd, args=args, error=err) return flask.jsonify(r.serialize())
def run_status(uid: str): """ :param uid: :return: """ try: r = server_runner.active_execution_responses.get(uid) if not r: return flask.jsonify(Response().update( run_log=[], run_active_uids=list( server_runner.active_execution_responses.keys()), run_status='unknown', run_multiple_updates=True, run_uid=uid, server=server_runner.get_server_data()).serialize()) if r.thread.is_running: try: step_changes = server_runner.get_running_step_changes(True) except Exception: step_changes = None return flask.jsonify(Response().update( run_log=r.get_thread_log(), run_status='running', run_multiple_updates=True, run_uid=uid, step_changes=step_changes, server=server_runner.get_server_data()).serialize()) del server_runner.active_execution_responses[uid] return flask.jsonify( r.update(run_log=r.get_thread_log(), run_status='complete', run_multiple_updates=True, run_uid=r.thread.uid).serialize()) except Exception as err: return flask.jsonify(Response().fail( code='COMMAND_RUN_STATUS_FAILURE', message='Unable to check command execution status', error=err, run_uid=uid).response.serialize())
def server_status(): """ :return: """ r = Response() r.update(success=True, server=server_runner.get_server_data()) return flask.jsonify(r.serialize())
def server_status(): """ :return: """ r = Response() r.update( success=True, server=server_runner.get_server_data() ).notify( kind='CONNECTED', code='RECEIVED_PING', message='Established remote connection' ).console(whitespace=1) return flask.jsonify(r.serialize())
def project_status(): """...""" r = Response() try: project = cauldron.project.get_internal_project() if project: r.update(project=project.status()) else: r.update(project=None) except Exception as err: r.fail( code='PROJECT_STATUS_ERROR', message='Unable to check status of currently opened project', error=err ) r.update(server=server_runner.get_server_data()) return flask.jsonify(r.serialize())
def execute(asynchronous: bool = False): """ :param asynchronous: Whether or not to allow asynchronous command execution that returns before the command is complete with a run_uid that can be used to track the continued execution of the command until completion. """ r = Response() r.update(server=server_runner.get_server_data()) cmd, args = parse_command_args(r) if r.failed: return flask.jsonify(r.serialize()) try: commander.execute(cmd, args, r) if not r.thread: return flask.jsonify(r.serialize()) if not asynchronous: r.thread.join() server_runner.active_execution_responses[r.thread.uid] = r # Watch the thread for a bit to see if the command finishes in # that time. If it does the command result will be returned directly # to the caller. Otherwise, a waiting command will be issued count = 0 while count < 5: count += 1 r.thread.join(0.25) if not r.thread.is_alive(): break if r.thread.is_alive(): return flask.jsonify( Response() .update( run_log=r.get_thread_log(), run_status='running', run_uid=r.thread.uid, step_changes=server_runner.get_running_step_changes(True), server=server_runner.get_server_data() ) .serialize() ) del server_runner.active_execution_responses[r.thread.uid] r.update( run_log=r.get_thread_log(), run_status='complete', run_multiple_updates=False, run_uid=r.thread.uid ) except Exception as err: r.fail( code='KERNEL_EXECUTION_FAILURE', message='Unable to execute command', cmd=cmd, args=args, error=err ) return flask.jsonify(r.serialize())
request_data='{}'.format(request.data), request_args=request_args) return name, args def execute(async: bool = False): """ :param async: Whether or not to allow asynchronous command execution that returns before the command is complete with a run_uid that can be used to track the continued execution of the command until completion. """ r = Response() r.update(server=server_runner.get_server_data()) cmd, args = parse_command_args(r) if r.failed: return flask.jsonify(r.serialize()) try: commander.execute(cmd, args, r) if not r.thread: return flask.jsonify(r.serialize()) if not async: r.thread.join() server_runner.active_execution_responses[r.thread.uid] = r
def run_status(uid: str): """ :param uid: :return: """ try: r = server_runner.active_execution_responses.get(uid) if not r: return flask.jsonify( Response().update( run_log=[], run_active_uids=list( server_runner.active_execution_responses.keys() ), run_status='unknown', run_multiple_updates=True, run_uid=uid, server=server_runner.get_server_data() ).serialize() ) if r.thread.is_running: try: step_changes = server_runner.get_running_step_changes(True) except Exception: step_changes = None return flask.jsonify( Response() .update( run_log=r.get_thread_log(), run_status='running', run_multiple_updates=True, run_uid=uid, step_changes=step_changes, server=server_runner.get_server_data() ).serialize() ) del server_runner.active_execution_responses[uid] return flask.jsonify( r.update( run_log=r.get_thread_log(), run_status='complete', run_multiple_updates=True, run_uid=r.thread.uid ).serialize() ) except Exception as err: return flask.jsonify( Response().fail( code='COMMAND_RUN_STATUS_FAILURE', message='Unable to check command execution status', error=err, run_uid=uid ).response.serialize() )
request_args=request_args ) return name, args def execute(async: bool = False): """ :param async: Whether or not to allow asynchronous command execution that returns before the command is complete with a run_uid that can be used to track the continued execution of the command until completion. """ r = Response() r.update(server=server_runner.get_server_data()) cmd, args = parse_command_args(r) if r.failed: return flask.jsonify(r.serialize()) try: commander.execute(cmd, args, r) if not r.thread: return flask.jsonify(r.serialize()) if not async: r.thread.join() server_runner.active_execution_responses[r.thread.uid] = r