Exemplo n.º 1
0
 def get_steps(task_key):
     session = db_session()
     try:
         result = session.query(StepMeta).filter(
             StepMeta.task_key == task_key).order_by(
                 StepMeta.order_id).all()
         if result:
             return result
         return []
     finally:
         session.close()
Exemplo n.º 2
0
 def get_steps_by_task_id(task_queue_id):
     session = db_session()
     try:
         result = session.query(StepExecute).filter(
             StepExecute.task_execute_id == task_queue_id).order_by(
                 StepExecute.id.desc()).all()
         if result:
             return result
         return []
     finally:
         session.close()
Exemplo n.º 3
0
    def save_step_context(self, context):
        # 保存任务上下文
        session = db_session()
        try:
            result = session.query(TaskExecute).filter(
                TaskExecute.id == self.id).update({"context": context})
            if result == 0:
                raise Exception("no match")

            session.commit()
        finally:
            session.close()
Exemplo n.º 4
0
 def get_created_task_queue(limit=10):
     # 从task queue获取待执行的任务
     session = db_session()
     try:
         result = session.query(TaskExecute).filter(
             TaskExecute.status == TaskStatus.created).order_by(
                 TaskExecute.id.desc()).limit(limit).offset(0).all()
         if result:
             return result
         return []
     finally:
         session.close()
Exemplo n.º 5
0
 def get_step(task_execute_id, step_name):
     # 获取真正执行的某一步的信息
     session = db_session()
     try:
         result = session.query(StepExecute).filter(
             StepExecute.task_execute_id == task_execute_id,
             StepExecute.step_name == step_name).first()
         if result:
             return result
         raise Exception("error")
     finally:
         session.close()
Exemplo n.º 6
0
    def add_exec_log(self, record):
        session = db_session()
        try:
            result = session.query(StepExecute).filter(
                StepExecute.id == self.id, ).first()
            if result:
                if result.exec_log:
                    result.exec_log = "{}\n{}".format(result.exec_log, record)

                session.flush()
                session.commit()
        finally:
            session.close()
Exemplo n.º 7
0
    def set_step_status(self, status):
        # todo 限定status的取值
        # 设置该step的状态
        session = db_session()
        try:
            result = session.query(StepExecute).filter(
                StepExecute.task_execute_id == self.task_execute_id,
                StepExecute.step_name == self.step_name,
            ).update({"status": status})
            if result == 0:
                raise Exception("no match")

            session.commit()
        finally:
            session.close()
Exemplo n.º 8
0
 def insert_steps(step_infos):
     # 跟task的新任务,实例化这个task
     session = db_session()
     try:
         for step_info in step_infos:
             session.add(
                 StepExecute(task_execute_id=step_info["task_execute_id"],
                             task_key=step_info["task_key"],
                             step_name=step_info["step_name"],
                             status=step_info.get("status",
                                                  StepStatus.waiting),
                             exec_log=step_info.get("exec_log", "no log")))
         session.commit()
     finally:
         session.close()
Exemplo n.º 9
0
    def get_task_by_id(id):
        """
        get task by id
        :param id:
        :return:
        """
        session = db_session()
        try:
            result = session.query(TaskExecute).filter(
                TaskExecute.id == id).first()
            if not result:
                raise Exception("get task error. no task id is {}".format(id))
            return result

        finally:
            session.close()
Exemplo n.º 10
0
    def update_status(self, status, step_name=None):
        """
        更新task的状态
        :param status:
        :param step_name: 方便结束或者中断的时候设置step name
        :return:
        """
        session = db_session()
        try:

            data = {"status": status}
            if step_name:
                data["step_name"] = step_name
            result = session.query(TaskExecute).filter(
                TaskExecute.id == self.id, ).update(data)
            if result == 0:
                raise Exception("no match")

            session.commit()
        finally:
            session.close()