Пример #1
0
def get_undo_task(task_type_name) -> list:
    """
    [
        task_type_name 是storage.models定义的数据库模型
        主要逻辑,根据task_type_name 从数据库中获得要执行的任务,任务队列
    ]

    Arguments:
        task_type_name {type} -- [description]

    Returns:
        list -- [description]
    """
    if not issubclass(task_type_name, AbstractTask):
        # todo 报告一次异常.
        return []
    query_result_list = []
    try:
        db = SessionLocal()
        obj = db.query(task_type_name).filter(
            or_(
                task_type_name.status == TaskStatusEnum.init,
                and_(
                    task_type_name.status == TaskStatusEnum.processing,
                    task_type_name.last_updatime + timedelta(seconds=120) <
                    datetime.now()))).first()
        if obj is not None:
            query_result_list = [obj]
    except Exception as e:
        print(e)
    finally:
        db.close()
    return query_result_list
Пример #2
0
 def save(self):
     try:
         db = SessionLocal()
         db.add(self)
         db.commit()
         db.refresh(self)
     except Exception as e:
         print(e)
     finally:
         db.close()
Пример #3
0
def get_undo_change_password_tasks():
    query_result_list=[]
    try:
        db = SessionLocal()
        obj=db.query(models.ChangePasswordTask).filter(
        or_(
            models.ChangePasswordTask.status == schemas.TaskStatusEnum.init,
            and_(models.ChangePasswordTask.status == schemas.TaskStatusEnum.processing , models.ChangePasswordTask.last_updatime + timedelta(seconds=120) < datetime.now() )
            )
        ).first()
        if obj is not None:
            query_result_list=[obj]
    except Exception as e:
        print(e)
    finally :
        db.close()
    return query_result_list