当前位置: 首页>>代码示例>>Python>>正文


Python Database.count_processing_tasks方法代码示例

本文整理汇总了Python中lib.cuckoo.core.database.Database.count_processing_tasks方法的典型用法代码示例。如果您正苦于以下问题:Python Database.count_processing_tasks方法的具体用法?Python Database.count_processing_tasks怎么用?Python Database.count_processing_tasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.cuckoo.core.database.Database的用法示例。


在下文中一共展示了Database.count_processing_tasks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scheduler

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_processing_tasks [as 别名]
def scheduler():
    db = Database()
    threshold = 32

    while True:
        tps = db.list_processing_tasks(None, 128)
        if not tps:
            log.info("No task processing instances available at the moment.")

        for tp in tps:
            # Subtracting one to account for the instance entry.
            count = db.count_processing_tasks(instance=tp.instance)-1
            log.debug("Scheduling for.. %s [tasks=%d]", tp.instance, count)

            if count > threshold:
                continue

            tasks = db.processing_get_new_tasks(threshold)
            for task in tasks:
                tp = TaskProcessing(task.id, tp.instance)
                db.add_processing_task(tp)

            log.debug("Assigned %d tasks to instance %s",
                      len(tasks), instance)

        time.sleep(1)
开发者ID:LittleHann,项目名称:cuckoo-linux,代码行数:28,代码来源:process2.py

示例2: instance

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_processing_tasks [as 别名]
def instance(instance):
    maxcount = cfg.cuckoo.max_analysis_count
    count = 0
    db = Database()

    try:
        while not maxcount or count != maxcount:
            if maxcount:
                limit = min(maxcount - count, 32)
            else:
                limit = 32

            tps = db.list_processing_tasks(instance=instance, count=limit)

            # No new tasks, we can wait a small while before we query again
            # for new tasks.
            if not tps:
                # Just make sure this instance is still available - it is not
                # if the scheduler has been restarted. In that case there will
                # be no records at all for this processing task.
                if not db.count_processing_tasks(instance):
                    log.info("This instance (%s) is not available anymore, "
                             "stopping.", instance)
                    break

                time.sleep(1)
                continue

            for tp in tps:
                task = db.view_task(tp.task_id)
                if task.status != TASK_COMPLETED:
                    log.warning("Task #%d: status (%s) is not completed, "
                                "ignoring", task.id, task.status)
                    continue

                log.info("Task #%d: reporting task", task.id)

                if task.category == "file":
                    sample = db.view_sample(task.sample_id)

                    copy_path = os.path.join(CUCKOO_ROOT, "storage",
                                             "binaries", sample.sha256)
                else:
                    copy_path = None

                try:
                    process(task.target, copy_path, task=task.to_dict(),
                            report=True, auto=True)
                    db.set_status(task.id, TASK_REPORTED)
                except Exception as e:
                    log.exception("Task #%d: error reporting: %s", task.id, e)
                    db.set_status(task.id, TASK_FAILED_PROCESSING)

                db.delete_processing_task(tp)
    except KeyboardInterrupt:
        raise
    except Exception as e:
        log.exception("Caught unknown exception: %s", e)
开发者ID:LittleHann,项目名称:cuckoo-linux,代码行数:60,代码来源:process2.py


注:本文中的lib.cuckoo.core.database.Database.count_processing_tasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。