From c9d52a5b7f230606449b6dc7b2b496ce4bc83dc7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 11 Apr 2024 18:30:36 +0100 Subject: [PATCH] feat: when no action to take, wait 10 seconds then restart As a stop-gap until we have a working webhook server, this will poll the repo for updates to it's status. Closes kemitix/git-next#22 --- src/server/actors/repo/mod.rs | 3 +-- src/server/actors/repo/status.rs | 6 ++++-- src/server/actors/repo/webhook.rs | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/server/actors/repo/mod.rs b/src/server/actors/repo/mod.rs index b848201..5718e91 100644 --- a/src/server/actors/repo/mod.rs +++ b/src/server/actors/repo/mod.rs @@ -133,8 +133,7 @@ impl Handler for RepoActor { } 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 + .wait(ctx); } } } diff --git a/src/server/actors/repo/status.rs b/src/server/actors/repo/status.rs index 82ed3fb..11b04f4 100644 --- a/src/server/actors/repo/status.rs +++ b/src/server/actors/repo/status.rs @@ -3,6 +3,7 @@ use gix::trace::warn; use tracing::info; use crate::server::{ + actors::repo::ValidateRepo, config::{self, ForgeType}, forge, }; @@ -28,12 +29,13 @@ pub async fn check_next( } Status::Pending => { info!("Checks are pending"); - } // TODO: (#22) wait and try again OR can webhook tell us when it's done, in - // which case we can do nothing here and wait for the webhook to trigger + } Status::Fail => { warn!("Checks have failed"); } } + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + addr.do_send(ValidateRepo); } #[derive(Debug)] diff --git a/src/server/actors/repo/webhook.rs b/src/server/actors/repo/webhook.rs index 65fb5cc..448bcef 100644 --- a/src/server/actors/repo/webhook.rs +++ b/src/server/actors/repo/webhook.rs @@ -1,5 +1,7 @@ use std::ops::Deref; +use crate::server::actors::repo::ValidateRepo; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct WebhookId(String); impl WebhookId { @@ -27,8 +29,10 @@ pub async fn unregister( pub async fn register( _repo_details: crate::server::config::RepoDetails, - _addr: actix::prelude::Addr, + addr: actix::prelude::Addr, _net: kxio::network::Network, ) { // TODO: (#15) register webhook - on success send webhook id to RepoActor + tokio::time::sleep(std::time::Duration::from_secs(10)).await; + addr.do_send(ValidateRepo); }