feat(server): Assess next action for repo
This commit is contained in:
parent
cdaca8258d
commit
70e0f94042
4 changed files with 104 additions and 2 deletions
|
@ -66,3 +66,12 @@ pub async fn validate_positions(
|
||||||
let dev = commit_histories.dev[0].clone();
|
let dev = commit_histories.dev[0].clone();
|
||||||
addr.do_send(StartMonitoring { main, next, dev });
|
addr.do_send(StartMonitoring { main, next, dev });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn advance_next(
|
||||||
|
_next: forge::Commit,
|
||||||
|
_repo_details: crate::server::config::RepoDetails,
|
||||||
|
_addr: actix::prelude::Addr<super::RepoActor>,
|
||||||
|
_net: kxio::network::Network,
|
||||||
|
) {
|
||||||
|
// TODO: (#14) advance next one commit towards dev
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod branch;
|
mod branch;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod status;
|
||||||
|
mod webhook;
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use kxio::network::Network;
|
use kxio::network::Network;
|
||||||
|
@ -10,9 +12,12 @@ use crate::server::{
|
||||||
forge,
|
forge,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use self::webhook::WebhookId;
|
||||||
|
|
||||||
pub struct RepoActor {
|
pub struct RepoActor {
|
||||||
details: RepoDetails,
|
details: RepoDetails,
|
||||||
config: Option<RepoConfig>, // INFO: if [None] then send [StartRepo] to populate it
|
config: Option<RepoConfig>, // INFO: if [None] then send [StartRepo] to populate it
|
||||||
|
webhook_id: Option<WebhookId>, // INFO: if [None] then no webhook is configured
|
||||||
net: Network,
|
net: Network,
|
||||||
}
|
}
|
||||||
impl RepoActor {
|
impl RepoActor {
|
||||||
|
@ -20,12 +25,27 @@ impl RepoActor {
|
||||||
Self {
|
Self {
|
||||||
details,
|
details,
|
||||||
config: None,
|
config: None,
|
||||||
|
webhook_id: None,
|
||||||
net,
|
net,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Actor for RepoActor {
|
impl Actor for RepoActor {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
|
fn stopping(&mut self, ctx: &mut Self::Context) -> Running {
|
||||||
|
match self.webhook_id.take() {
|
||||||
|
Some(webhook_id) => {
|
||||||
|
let repo_details = self.details.clone();
|
||||||
|
let addr = ctx.address();
|
||||||
|
let net = self.net.clone();
|
||||||
|
webhook::unregister(webhook_id, repo_details, addr, net)
|
||||||
|
.into_actor(self)
|
||||||
|
.wait(ctx);
|
||||||
|
Running::Continue
|
||||||
|
}
|
||||||
|
None => Running::Stop,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -69,7 +89,36 @@ pub struct StartMonitoring {
|
||||||
}
|
}
|
||||||
impl Handler<StartMonitoring> for RepoActor {
|
impl Handler<StartMonitoring> for RepoActor {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, _msg: StartMonitoring, _ctx: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: StartMonitoring, ctx: &mut Self::Context) -> Self::Result {
|
||||||
info!(%self.details, "Monitoring started");
|
info!("Monitoring started");
|
||||||
|
let next_ahead_of_main = msg.main != msg.next;
|
||||||
|
let dev_ahead_of_next = msg.next != msg.dev;
|
||||||
|
let repo_details = self.details.clone();
|
||||||
|
let addr = ctx.address();
|
||||||
|
let net = self.net.clone();
|
||||||
|
if next_ahead_of_main {
|
||||||
|
status::check_next(msg.next, repo_details, addr, net)
|
||||||
|
.into_actor(self)
|
||||||
|
.wait(ctx);
|
||||||
|
} else if dev_ahead_of_next {
|
||||||
|
branch::advance_next(msg.next, repo_details, addr, net)
|
||||||
|
.into_actor(self)
|
||||||
|
.wait(ctx);
|
||||||
|
} else if self.webhook_id.is_none() {
|
||||||
|
webhook::register(repo_details, addr, net)
|
||||||
|
.into_actor(self)
|
||||||
|
.wait(ctx)
|
||||||
|
// TODO: (#18) watch for changes on dev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
#[rtype(result = "()")]
|
||||||
|
pub struct WebhookRegistered(pub WebhookId);
|
||||||
|
impl Handler<WebhookRegistered> for RepoActor {
|
||||||
|
type Result = ();
|
||||||
|
fn handle(&mut self, msg: WebhookRegistered, _ctx: &mut Self::Context) -> Self::Result {
|
||||||
|
self.webhook_id.replace(msg.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/server/actors/repo/status.rs
Normal file
10
src/server/actors/repo/status.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use crate::server::forge;
|
||||||
|
|
||||||
|
pub async fn check_next(
|
||||||
|
_next: forge::Commit,
|
||||||
|
_repo_details: crate::server::config::RepoDetails,
|
||||||
|
_addr: actix::prelude::Addr<super::RepoActor>,
|
||||||
|
_net: kxio::network::Network,
|
||||||
|
) {
|
||||||
|
// TODO: (#13) check statuses for next head - if ok, advance main to next and reassess
|
||||||
|
}
|
34
src/server/actors/repo/webhook.rs
Normal file
34
src/server/actors/repo/webhook.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub struct WebhookId(String);
|
||||||
|
impl WebhookId {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub const fn new(id: String) -> Self {
|
||||||
|
Self(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Deref for WebhookId {
|
||||||
|
type Target = String;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn unregister(
|
||||||
|
_webhook_id: WebhookId,
|
||||||
|
_repo_details: crate::server::config::RepoDetails,
|
||||||
|
_addr: actix::prelude::Addr<super::RepoActor>,
|
||||||
|
_net: kxio::network::Network,
|
||||||
|
) {
|
||||||
|
// TODO: (#17) unregister webhook
|
||||||
|
// on success - stop the actor
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn register(
|
||||||
|
_repo_details: crate::server::config::RepoDetails,
|
||||||
|
_addr: actix::prelude::Addr<super::RepoActor>,
|
||||||
|
_net: kxio::network::Network,
|
||||||
|
) {
|
||||||
|
// TODO: (#15) register webhook - on success send webhook id to RepoActor
|
||||||
|
}
|
Loading…
Reference in a new issue