feat: add common queue
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-11-24 21:08:37 +01:00
parent ee323e99e8
commit ea5adb2f93
15 changed files with 271 additions and 85 deletions

View File

@@ -2,7 +2,14 @@ use std::{ops::Deref, sync::Arc};
use crate::api::Discovery;
use super::{config::AgentConfig, discovery_client::DiscoveryClient, grpc_client::GrpcClient};
use super::{
config::AgentConfig,
discovery_client::DiscoveryClient,
grpc_client::GrpcClient,
handlers::scheduled_tasks::{self, ScheduledTasks},
queue::AgentQueue,
scheduler::Scheduler,
};
#[derive(Clone)]
pub struct AgentState(Arc<State>);
@@ -31,20 +38,23 @@ pub struct State {
pub grpc: GrpcClient,
pub config: AgentConfig,
pub discovery: Discovery,
pub queue: AgentQueue,
}
impl State {
pub async fn new() -> anyhow::Result<Self> {
let config = AgentConfig::new().await?;
let discovery = DiscoveryClient::new(&config.discovery);
let discovery = discovery.discover().await?;
let discovery = DiscoveryClient::new(&config.discovery).discover().await?;
let grpc = GrpcClient::new(&discovery.process_host);
let scheduled_tasks = ScheduledTasks::new();
let scheduler = Scheduler::new(scheduled_tasks);
let queue = AgentQueue::new(scheduler);
Ok(Self {
grpc,
config,
discovery,
queue,
})
}
}