database.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:CAPE 作者: ctxis 项目源码 文件源码
def fetch(self, lock=True, machine=""):
        """Fetches a task waiting to be processed and locks it for running.
        @return: None or task
        """
        session = self.Session()
        row = None
        try:
            if machine != "":
                row = session.query(Task).filter_by(status=TASK_PENDING).filter_by(machine=machine).order_by("priority desc, added_on").first()
            else:
                row = session.query(Task).filter_by(status=TASK_PENDING).order_by("priority desc, added_on").first()

            if not row:
                return None

            if lock:
                self.set_status(task_id=row.id, status=TASK_RUNNING)
                session.refresh(row)

            return row
        except SQLAlchemyError as e:
            log.debug("Database error fetching task: {0}".format(e))
            session.rollback()
        finally:
            session.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号