예제 #1
0
파일: worker.py 프로젝트: GrimDerp/WALKOFF
    async def run():
        async with connect_to_redis_pool(config.REDIS_URI) as redis, \
                aiohttp.ClientSession(json_serialize=message_dumps) as session:

            # Attach our signal handlers to cleanly close services we've created
            loop = asyncio.get_running_loop()
            loop.add_signal_handler(
                signal.SIGINT,
                lambda: asyncio.ensure_future(Worker.shutdown()))
            loop.add_signal_handler(
                signal.SIGTERM,
                lambda: asyncio.ensure_future(Worker.shutdown()))

            async for workflow in Worker.get_workflow(redis):

                # Setup worker and results stream
                worker = Worker(workflow, redis=redis, session=session)

                # Attach our abort signal handler to a specific instance of the worker
                loop.add_signal_handler(
                    signal.SIGQUIT,
                    lambda: asyncio.ensure_future(worker.abort()))

                log_msg = f"workflow: {workflow.name} ({workflow.id_}) as {workflow.execution_id}"

                await redis.xgroup_create(worker.results_stream,
                                          static.REDIS_ACTION_RESULTS_GROUP,
                                          mkstream=True)
                logger.info(f"Starting {log_msg}")
                status = WorkflowStatusMessage.execution_started(
                    worker.workflow.execution_id, worker.workflow.id_,
                    worker.workflow.name)

                await send_status_update(session, workflow.execution_id,
                                         status)

                try:
                    worker.execution_task = asyncio.create_task(
                        worker.execute_workflow())
                    await asyncio.gather(worker.execution_task)
                except asyncio.CancelledError:
                    logger.info(f"Aborting {log_msg}")
                    status = WorkflowStatusMessage.execution_aborted(
                        worker.workflow.execution_id, worker.workflow.id_,
                        worker.workflow.name)
                except Exception:
                    logger.info(f"Failed {log_msg}")
                    status = WorkflowStatusMessage.execution_completed(
                        worker.workflow.execution_id, worker.workflow.id_,
                        worker.workflow.name)
                else:
                    logger.info(f"Completed {log_msg}")
                    status = WorkflowStatusMessage.execution_completed(
                        worker.workflow.execution_id, worker.workflow.id_,
                        worker.workflow.name)
                finally:
                    await send_status_update(session, workflow.execution_id,
                                             status)

            await Worker.shutdown()
예제 #2
0
파일: umpire.py 프로젝트: GrimDerp/WALKOFF
    async def run(autoscale_worker, autoscale_app, autoheal_worker,
                  autoheal_apps):
        async with connect_to_redis_pool(config.REDIS_URI) as redis, aiohttp.ClientSession() as session, \
                connect_to_aiodocker() as docker_client:
            ump = await Umpire.init(docker_client=docker_client,
                                    redis=redis,
                                    session=session,
                                    autoscale_worker=autoscale_worker,
                                    autoscale_app=autoscale_app,
                                    autoheal_worker=autoheal_worker,
                                    autoheal_apps=autoheal_apps)

            # Attach our signal handler to cleanly close services we've created
            loop = asyncio.get_running_loop()
            for signame in {'SIGINT', 'SIGTERM'}:
                loop.add_signal_handler(
                    getattr(signal, signame),
                    lambda: asyncio.ensure_future(ump.shutdown()))

            logger.info("Bringing up Umpire API...")
            os.system("uvicorn umpire_api:app --host 0.0.0.0 &")

            logger.info("Umpire is ready!")
            await asyncio.gather(
                asyncio.create_task(ump.workflow_control_listener()),
                asyncio.create_task(ump.monitor_queues()))
        await ump.shutdown()
예제 #3
0
파일: build.py 프로젝트: shwinnbin/WALKOFF
async def build_image(request: BuildImage):
    success, message = await MinioApi.build_image(request.app_name,
                                                  request.app_version)

    if success:
        try:
            saved = await MinioApi.save_file(request.app_name,
                                             request.app_version)
        except Exception as e:
            return {
                "build_id": "None",
                "status": "Failed to save changes locally."
            }
    else:
        return {"build_id": "None", "status": message}

    async with aiohttp.ClientSession() as session:
        app_repo = await AppRepo.create(config.APPS_PATH, session)

    build_id = str(uuid.uuid4())
    redis_key = BUILD_STATUS_GLOB + "." + request.app_name + "." + build_id
    build_id = request.app_name + "." + build_id
    async with connect_to_redis_pool(config.REDIS_URI) as conn:
        await conn.execute('set', redis_key, "BUILDING")
        ret = {"build_id": build_id, "status": "Success"}
        return ret
예제 #4
0
파일: build.py 프로젝트: shwinnbin/WALKOFF
async def get_build_statuses():
    async with connect_to_redis_pool(config.REDIS_URI) as conn:
        ret = []
        build_keys = set(await conn.keys(pattern=BUILD_STATUS_GLOB + "*",
                                         encoding="utf-8"))
        for key in build_keys:
            build = await conn.execute('get', key)
            build = build.decode('utf-8')
            ret.append((key, build))
        return f"List of Current Builds: {ret}"
예제 #5
0
파일: build.py 프로젝트: shwinnbin/WALKOFF
async def build_status_from_id(build_id):
    async with connect_to_redis_pool(config.REDIS_URI) as conn:
        get = BUILD_STATUS_GLOB + "." + build_id
        build_status = await conn.execute('get', get)
        build_status = build_status.decode('utf-8')
        return build_status