2024-04-09 15:31:59 +01:00
|
|
|
mod branch;
|
2024-04-09 10:44:01 +01:00
|
|
|
mod config;
|
|
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
|
use kxio::network::Network;
|
|
|
|
use tracing::info;
|
|
|
|
|
2024-04-09 18:18:19 +01:00
|
|
|
use crate::server::{
|
|
|
|
config::{RepoConfig, RepoDetails},
|
|
|
|
forge,
|
|
|
|
};
|
2024-04-09 10:44:01 +01:00
|
|
|
|
|
|
|
pub struct RepoActor {
|
|
|
|
details: RepoDetails,
|
|
|
|
config: Option<RepoConfig>, // INFO: if [None] then send [StartRepo] to populate it
|
|
|
|
net: Network,
|
|
|
|
}
|
|
|
|
impl RepoActor {
|
|
|
|
pub(crate) const fn new(details: RepoDetails, net: Network) -> Self {
|
|
|
|
Self {
|
|
|
|
details,
|
|
|
|
config: None,
|
|
|
|
net,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Actor for RepoActor {
|
|
|
|
type Context = Context<Self>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct StartRepo;
|
|
|
|
impl Handler<StartRepo> for RepoActor {
|
|
|
|
type Result = ();
|
|
|
|
fn handle(&mut self, _msg: StartRepo, ctx: &mut Self::Context) -> Self::Result {
|
|
|
|
info!(%self.details, "Starting Repo");
|
|
|
|
let details = self.details.clone();
|
|
|
|
let addr = ctx.address();
|
|
|
|
let net = self.net.clone();
|
|
|
|
config::load(details, addr, net).into_actor(self).wait(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
struct LoadedConfig(pub RepoConfig);
|
|
|
|
impl Handler<LoadedConfig> for RepoActor {
|
|
|
|
type Result = ();
|
2024-04-09 15:31:59 +01:00
|
|
|
fn handle(&mut self, msg: LoadedConfig, ctx: &mut Self::Context) -> Self::Result {
|
2024-04-09 10:44:01 +01:00
|
|
|
let config = msg.0;
|
|
|
|
info!(%self.details, %config, "Config loaded");
|
2024-04-09 15:31:59 +01:00
|
|
|
self.config.replace(config.clone());
|
2024-04-09 16:16:01 +01:00
|
|
|
let repo_details = self.details.clone();
|
2024-04-09 15:31:59 +01:00
|
|
|
let addr = ctx.address();
|
|
|
|
let net = self.net.clone();
|
2024-04-09 16:16:01 +01:00
|
|
|
branch::validate_positions(repo_details, config, addr, net)
|
2024-04-09 15:31:59 +01:00
|
|
|
.into_actor(self)
|
|
|
|
.wait(ctx);
|
2024-04-09 10:44:01 +01:00
|
|
|
}
|
|
|
|
}
|
2024-04-09 18:18:19 +01:00
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct StartMonitoring {
|
|
|
|
pub main: forge::Commit,
|
|
|
|
pub next: forge::Commit,
|
|
|
|
pub dev: forge::Commit,
|
|
|
|
}
|
|
|
|
impl Handler<StartMonitoring> for RepoActor {
|
|
|
|
type Result = ();
|
|
|
|
fn handle(&mut self, _msg: StartMonitoring, _ctx: &mut Self::Context) -> Self::Result {
|
|
|
|
info!(%self.details, "Monitoring started");
|
|
|
|
}
|
|
|
|
}
|