Example #1
0
def job_garbage_collector():
    result = db_session.query(Workflows.id).all()
    notin_list_tuple = tuple([r[0] for r in result])
    result = db_session.query(WorkflowJobs.id).filter(
        ~WorkflowJobs.wf_id.in_(notin_list_tuple)).distinct()
    in_list_tuple = tuple([r[0] for r in result])
    if in_list_tuple:
        delete_q = WorkflowJobs.__table__.delete().where(
            WorkflowJobs.id.in_(in_list_tuple))
        db_session.execute(delete_q)
        db_session.commit()
    return True
Example #2
0
def get_db_table_is_empty(table_name):
    if (table_name == 'User'):
        result = db_session.query(User.id).all()
    elif (table_name == 'Workflows'):
        result = db_session.query(Workflows.id).all()
    elif (table_name == 'WorkflowJobs'):
        result = db_session.query(WorkflowJobs.id).all()
    elif (table_name == 'WorkflowMessages'):
        result = db_session.query(WorkflowMessages.id).all()
    if len(result) <= 0:
        return True
    else:
        return False
    return
Example #3
0
def delete_db_wf(workflow_id):
    try:
        db_session.query(WorkflowMessages).filter(
            WorkflowMessages.wf_id == workflow_id).delete()
        db_session.query(WorkflowJobs).filter(
            WorkflowJobs.wf_id == workflow_id).delete()
        d_wf = Workflows.query.filter(Workflows.id == workflow_id).first()
        db_session.delete(d_wf)
        db_session.commit()
        msg_garbage_collector()
        job_garbage_collector()
        return True
    except:
        return False
Example #4
0
def delete_whole_db():
    try:
        db_session.query(WorkflowMessages).delete()
        db_session.query(WorkflowJobs).delete()
        db_session.query(Workflows).delete()
        db_session.commit()
        return True
    except:
        return False
Example #5
0
def get_db_workflows_by_status(workflow_id):
    return (db_session.query(
        Workflows.status).filter(Workflows.id == workflow_id).first())[0]