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 server_status(): """ :return: """ r = Response() r.update(success=True, server=server_runner.get_server_data()) return flask.jsonify(r.serialize())
def test_logging(self): """Should log messages to the log""" r = Response() r.notify( kind='TEST', code='TEST_MESSAGE', message='This is a test', ).console_header('Harold').console('Holly').console_raw('Handy') out = r.get_notification_log() self.assertGreater(out.find('Harold'), -1) self.assertGreater(out.find('Holly'), -1) self.assertGreater(out.find('Handy'), -1) r = Response.deserialize(r.serialize()) compare = r.get_notification_log() self.assertEqual(out, compare)
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 test_logging(self): """Should log messages to the log""" r = Response() r.notify( kind='TEST', code='TEST_MESSAGE', message='This is a test', ).console_header( 'Harold' ).console( 'Holly' ).console_raw( 'Handy' ) out = r.get_notification_log() self.assertGreater(out.find('Harold'), -1) self.assertGreater(out.find('Holly'), -1) self.assertGreater(out.find('Handy'), -1) r = Response.deserialize(r.serialize()) compare = r.get_notification_log() self.assertEqual(out, compare)
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())
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 # 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