def run(self, params, input_path, parser, output_path=None):
        """Runs the external tool 

		Args:
			parser (func):			function that takes stdout of run. If output to stdout is not possible, the path to the output needs to be provided as output_path
			output_path: 			path to output, for parser
		Returns:	output of parser
		"""

        if not os.path.exists(self.src):
            log.critical('Executable not found at provided location: ' +
                         self.src)
            raise IOError
        command = [self.src]
        command.extend(params)
        if input_path: command.append(input_path)

        # log.debug('Running {}:\n{}'.format(self.get_name(), ' '.join(command)))

        process = Popen(command, stdout=PIPE, stderr=PIPE)
        stdout, stderr = process.communicate()

        try:
            return parser(stdout.strip() if not output_path else output_path)
        except (IndexError, IOError, ValueError):
            log.error('{} failed'.format(self.get_name()))
            log.debug(stderr)
            log.debug(stdout)
            return None
示例#2
0
def log_uncaught_exceptions(ex_cls, ex, tb):
    text = '{}: {}:\n'.format(ex_cls.__name__, ex)
    text += ''.join(traceback.format_tb(tb))

    log.critical(text)
    QMessageBox.critical(None, 'Error', text)
    quit()
示例#3
0
    def run(src, params, input_path, output_path, mappings=False):
        import sys, stat
        if not os.path.exists(src):
            log.critical('DSF executable not found at provided location: ' +
                         src)
            raise IOError

        sys.path.append(os.path.split(src)[0])
        import dense_subgraph_finder

        command = [
            x for x in [src, params, '--graph', input_path, '-o', output_path]
            if x
        ]

        with open('temp.sh', 'wb+') as script:
            script.write('#!/bin/bash\n' + ' '.join(command))
            st = os.stat(script.name)
            os.chmod(script.name, st.st_mode | stat.S_IEXEC)
            log.debug('Script at: {}\n{}'.format(script.name, script.read()))
            process = subprocess.call('/bin/bash ' + script.name, shell=True)
            process = Popen(' '.join(command),
                            stdout=PIPE,
                            stderr=PIPE,
                            shell=True)
            stdout, stderr = process.communicate()

            print(stdout)
            print(stderr)

        log.info('Running Dense Subgraph Finder:\n{}'.format(
            ' '.join(command)))

        try:
            result = DSF.parse_dsf_output(path=output_path +
                                          '/dense_subgraphs.txt',
                                          mappings=mappings)
            return result
        except IOError as e:
            raise Exception('DSF failed, see debug log')
示例#4
0
    def run(self):
        while True:
            time.sleep(self.interval)
            tasks = query_timing_task()
            for task in tasks:
                if task.status not in [
                        TASK_STATUS_FINISHED, TASK_STATUS_INTERRUPT
                ]:
                    continue

                cur_time = int(time.time())
                start_time = str_to_tiem_stamp(str(task.start_time))
                peroid = int(task.execute_cycle)
                if cur_time - start_time < peroid:
                    continue

                redis_conn = redis.Redis(connection_pool=redis_pool)
                if task.task_type == TASK_RUN_TYPE_LINUX:
                    redis_conn.lpush(REDIS_LINUX_TASKS, str(
                        (task.id, "start")))
                elif task.task_type == TASK_RUN_TYPE_WINDOWS:
                    redis_conn.lpush(REDIS_WINDOWS_TASKS,
                                     str((task.id, "start")))
                else:
                    log.error("定时任务类型错误")
                    continue

                table_name = create_res_table(task.id)
                update_task(task.id, "res_table", table_name)
                update_task(task.id, "status", TASK_STATUS_PREPARING)
                log.critical("定时任务 {} 启动".format(task.id))

            nodes = query_nodes()
            for node in nodes:
                if node.status == NODE_STATUS_INVALID:
                    remove_node(node.id)
                    continue

                url = 'http://' + node.ip_addr + ':5000' + QUERY_NODE_STATUS_URL
                try:
                    response = requests.get(url=url, timeout=10)
                    ret = json.loads(response.text)
                    if ret['status'] == NODE_STATUS_NORMAL:
                        log.critical("Node {} is OK!".format(str(node.id)))
                        if node.status == NODE_STATUS_DISCONNECT:
                            update_node(node.id, 'status', NODE_STATUS_NORMAL)
                except Exception as e:
                    if node.status == NODE_STATUS_NORMAL:
                        update_node(node.id, 'status', NODE_STATUS_DISCONNECT)
                        log.critical("Node {} is disconnect! error={}".format(
                            str(node.id), str(e)))
                        continue

                    log.error("Node {} error={}".format(node.id, str(e)))
示例#5
0
def db_delete_node(node_id):
    Node.query.filter_by(id=node_id).delete()
    db.session.commit()
    log.critical("Node {} 被删除".format(node_id))
示例#6
0
 def log_critical(self, info):
     log.critical(info)
示例#7
0
def delete_node(node_id):
    session.query(Node).filter_by(id=node_id).delete()
    session.commit()
    log.critical("Node {} 被删除".format(node_id))
示例#8
0
 def log_critical(self, info):
     if self.log_switch:
         log.critical(info)