Ejemplo n.º 1
0
def post_flow_run(db: Session, flow_run: schemas.NaiveFlowRun):
    flow = Flow.ensure(db, flow_run.flow.name)
    flow_run = flow.latest_session.ensure_flow_run(db,
                                                   flow_run.key,
                                                   state=flow_run.state)
    db.commit()
    return flow_run
Ejemplo n.º 2
0
def post_task_run(db: Session, task_run: schemas.NaiveTaskRun):
    flow = Flow.ensure(db, task_run.flow_run.flow.name)
    task = flow.latest_session.ensure_task(db, task_run.task.name)
    flow_run = flow.latest_session.ensure_flow_run(db, task_run.flow_run.key)
    logger.debug(f"Task: {task.name}, ix: {task_run.map_index}")
    task_run = flow_run.ensure_task_run(db,
                                        task,
                                        state=task_run.state,
                                        map_index=task_run.map_index)
    db.commit()
    return task_run
Ejemplo n.º 3
0
def post_flow(db: Session, flow: schemas.NaiveFlow):
    f = Flow.ensure(
        db,
        flow.name,
        is_online=flow.is_online,
        schedule=flow.schedule,
        tasks=flow.tasks,
    )
    if not flow.is_online:
        f.shutdown()
    else:
        f.create_session(db, edges=flow.edges)
    db.commit()
    return f
Ejemplo n.º 4
0
async def db_session_middleware(request: Request, call_next):
    response = Response("Internal server error", status_code=500)
    try:
        request.state.db = Session()
        response = await call_next(request)
    finally:
        request.state.db.close()
    return response
Ejemplo n.º 5
0
 def run(self):
     logger = logging.getLogger(__name__)
     while not self._stop_signal.is_set():
         with closing(Session()) as db:
             for message in self.receive_messages():
                 try:
                     process_message(db, message)
                 except Exception as e:
                     logger.error(e)
         time.sleep(1)
Ejemplo n.º 6
0
def delete_flow(db: Session, flow_id: int):
    flow = db.query(Flow).get(flow_id)
    if not flow.is_online:
        db.delete(flow)
        db.commit()
    return get_flows(db)
Ejemplo n.º 7
0
def get_flow(db: Session, flow_id: int, flow_runs=10):
    flow = db.query(Flow).get(flow_id)
    flow_runs = (db.query(FlowRun).filter_by(flow=flow).order_by(
        FlowRun.id.desc()).limit(flow_runs).all())
    flow.flow_runs = sorted(flow_runs, key=lambda x: x.id)
    return flow
Ejemplo n.º 8
0
def get_flows(db: Session, offset: int = 0, limit: int = 10):
    return db.query(Flow).offset(offset).limit(limit).all()