From 03a17181f7cc70d31f2d06349c7f93e792e02d87 Mon Sep 17 00:00:00 2001 From: Christopher Bartz Date: Wed, 11 Sep 2024 11:04:54 +0200 Subject: [PATCH] add public interface --- src-docs/reactive.consumer.md | 32 +++++++++++++++---- src-docs/reactive.runner.md | 25 +++++++++++++-- .../reactive/consumer.py | 20 ++++++++++-- src/github_runner_manager/reactive/runner.py | 26 ++++++++++++++- 4 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src-docs/reactive.consumer.md b/src-docs/reactive.consumer.md index 99ce9ed..cc46433 100644 --- a/src-docs/reactive.consumer.md +++ b/src-docs/reactive.consumer.md @@ -8,12 +8,12 @@ Module responsible for consuming jobs from the message queue. --- - + ## function `consume` ```python -consume(mongodb_uri: str, queue_name: str) → None +consume(queue_config: QueueConfig, runner_manager: RunnerManager) → None ``` Consume a job from the message queue. @@ -24,8 +24,8 @@ Log the job details and acknowledge the message. If the job details are invalid, **Args:** - - `mongodb_uri`: The URI of the MongoDB database. - - `queue_name`: The name of the queue. + - `queue_config`: The configuration for the message queue. + - `runner_manager`: The runner manager used to create the runner. @@ -36,7 +36,7 @@ Log the job details and acknowledge the message. If the job details are invalid, --- - + ## function `signal_handler` @@ -57,7 +57,7 @@ The signal handler exits the process. --- - + ## class `JobDetails` A class to translate the payload. @@ -75,7 +75,25 @@ A class to translate the payload. --- - + + +## class `QueueConfig` +The configuration for the message queue. + + + +**Attributes:** + + - `mongodb_uri`: The URI of the MongoDB database. + - `queue_name`: The name of the queue. + + + + + +--- + + ## class `JobError` Raised when a job error occurs. diff --git a/src-docs/reactive.runner.md b/src-docs/reactive.runner.md index 83fd8b5..4a2dbd1 100644 --- a/src-docs/reactive.runner.md +++ b/src-docs/reactive.runner.md @@ -12,7 +12,7 @@ Script to spawn a reactive runner process. --- - + ## function `setup_root_logging` @@ -25,7 +25,7 @@ Set up logging for the reactive runner process. --- - + ## function `main` @@ -42,3 +42,24 @@ Spawn a process that consumes a message from the queue to create a runner. - `ValueError`: If the required environment variables are not set +--- + + + +## class `ReactiveRunnerConfig` +The configuration for the reactive runner to spawn. + + + +**Attributes:** + + - `queue`: The queue configuration. + - `runner_manager`: The runner manager configuration. + - `runner`: The GitHub runner configuration. + - `openstack_cloud`: The OpenStack cloud configuration. + - `openstack_server`: The OpenStack server configuration. + + + + + diff --git a/src/github_runner_manager/reactive/consumer.py b/src/github_runner_manager/reactive/consumer.py index f868fed..0a8fd56 100644 --- a/src/github_runner_manager/reactive/consumer.py +++ b/src/github_runner_manager/reactive/consumer.py @@ -13,6 +13,9 @@ from kombu import Connection from kombu.simple import SimpleQueue from pydantic import BaseModel, HttpUrl, ValidationError +from pydantic.networks import MongoDsn + +from github_runner_manager.manager.runner_manager import RunnerManager logger = logging.getLogger(__name__) @@ -28,20 +31,31 @@ class JobDetails(BaseModel): labels: list[str] run_url: HttpUrl +class QueueConfig(BaseModel): + """The configuration for the message queue. + + Attributes: + mongodb_uri: The URI of the MongoDB database. + queue_name: The name of the queue. + """ + + mongodb_uri: MongoDsn + queue_name: str + class JobError(Exception): """Raised when a job error occurs.""" -def consume(mongodb_uri: str, queue_name: str) -> None: +def consume(queue_config: QueueConfig, runner_manager: RunnerManager) -> None: """Consume a job from the message queue. Log the job details and acknowledge the message. If the job details are invalid, reject the message and raise an error. Args: - mongodb_uri: The URI of the MongoDB database. - queue_name: The name of the queue. + queue_config: The configuration for the message queue. + runner_manager: The runner manager used to create the runner. Raises: JobError: If the job details are invalid. diff --git a/src/github_runner_manager/reactive/runner.py b/src/github_runner_manager/reactive/runner.py index 415ce6d..7b85b5a 100644 --- a/src/github_runner_manager/reactive/runner.py +++ b/src/github_runner_manager/reactive/runner.py @@ -7,7 +7,13 @@ import os import sys -from github_runner_manager.reactive.consumer import consume +from pydantic import BaseModel + +from github_runner_manager.manager.cloud_runner_manager import GitHubRunnerConfig +from github_runner_manager.manager.runner_manager import RunnerManagerConfig +from github_runner_manager.openstack_cloud.openstack_runner_manager import OpenStackCloudConfig, \ + OpenStackServerConfig +from github_runner_manager.reactive.consumer import consume, QueueConfig from github_runner_manager.reactive.runner_manager import MQ_URI_ENV_VAR, QUEUE_NAME_ENV_VAR @@ -21,6 +27,24 @@ def setup_root_logging() -> None: ) +class ReactiveRunnerConfig(BaseModel): + """The configuration for the reactive runner to spawn. + + Attributes: + queue: The queue configuration. + runner_manager: The runner manager configuration. + runner: The GitHub runner configuration. + openstack_cloud: The OpenStack cloud configuration. + openstack_server: The OpenStack server configuration. + """ + + queue: QueueConfig + runner_manager: RunnerManagerConfig + runner: GitHubRunnerConfig + openstack_cloud: OpenStackCloudConfig + openstack_server: OpenStackServerConfig | None = None + + def main() -> None: """Spawn a process that consumes a message from the queue to create a runner.