예제 #1
0
async def progress_message_parser(app: web.Application, data: bytes) -> None:
    # update corresponding project, node, progress value
    rabbit_message = ProgressRabbitMessage.parse_raw(data)
    try:
        project = await projects_api.update_project_node_progress(
            app,
            rabbit_message.user_id,
            f"{rabbit_message.project_id}",
            f"{rabbit_message.node_id}",
            progress=rabbit_message.progress,
        )
        if project:
            messages: List[SocketMessageDict] = [{
                "event_type": SOCKET_IO_NODE_UPDATED_EVENT,
                "data": {
                    "project_id": project["uuid"],
                    "node_id": rabbit_message.node_id,
                    "data": project["workbench"][f"{rabbit_message.node_id}"],
                },
            }]
            await send_messages(app, f"{rabbit_message.user_id}", messages)
    except ProjectNotFoundError:
        log.warning(
            "project related to received rabbitMQ progress message not found: '%s'",
            json_dumps(rabbit_message, indent=2),
        )
    except NodeNotFoundError:
        log.warning(
            "node related to received rabbitMQ progress message not found: '%s'",
            json_dumps(rabbit_message, indent=2),
        )
예제 #2
0
 async def _task_progress_change_handler(self, event: str) -> None:
     task_progress_event = TaskProgressEvent.parse_raw(event)
     logger.debug("received task progress update: %s", task_progress_event)
     *_, user_id, project_id, node_id = parse_dask_job_id(task_progress_event.job_id)
     message = ProgressRabbitMessage(
         user_id=user_id,
         project_id=project_id,
         node_id=node_id,
         progress=task_progress_event.progress,
     )
     await self.rabbitmq_client.publish_message(message)
예제 #3
0
async def _publish_in_rabbit(
    user_id: int,
    project_id: UUIDStr,
    node_uuid: UUIDStr,
    num_messages: int,
    rabbit_exchanges: RabbitExchanges,
) -> Tuple[LogMessages, ProgressMessages, InstrumMessages]:

    log_messages = [
        LoggerRabbitMessage(
            user_id=user_id,
            project_id=project_id,
            node_id=node_uuid,
            messages=[f"log number {n}"],
        ) for n in range(num_messages)
    ]
    progress_messages = [
        ProgressRabbitMessage(
            user_id=user_id,
            project_id=project_id,
            node_id=node_uuid,
            progress=float(n) / float(num_messages),
        ) for n in range(num_messages)
    ]

    # indicate container is started
    instrumentation_start_message = (
        instrumentation_stop_message) = InstrumentationRabbitMessage(
            metrics="service_started",
            user_id=user_id,
            project_id=project_id,
            node_id=node_uuid,
            service_uuid=node_uuid,
            service_type="COMPUTATIONAL",
            service_key="some/service/awesome/key",
            service_tag="some-awesome-tag",
        )
    instrumentation_stop_message.metrics = "service_stopped"
    instrumentation_stop_message.result = RunningState.SUCCESS
    instrumentation_messages = [
        instrumentation_start_message,
        instrumentation_stop_message,
    ]
    await rabbit_exchanges.instrumentation.publish(
        aio_pika.Message(
            body=instrumentation_start_message.json().encode(),
            content_type="text/json",
        ),
        routing_key="",
    )

    for n in range(num_messages):
        await rabbit_exchanges.logs.publish(
            aio_pika.Message(body=log_messages[n].json().encode(),
                             content_type="text/json"),
            routing_key="",
        )

        await rabbit_exchanges.progress.publish(
            aio_pika.Message(body=progress_messages[n].json().encode(),
                             content_type="text/json"),
            routing_key="",
        )

    # indicate container is stopped
    await rabbit_exchanges.instrumentation.publish(
        aio_pika.Message(
            body=instrumentation_stop_message.json().encode(),
            content_type="text/json",
        ),
        routing_key="",
    )

    return (log_messages, progress_messages, instrumentation_messages)