forked from kemitix/git-next
refactor: split server storage creation out from startup
Closes kemitix/git-next#75
This commit is contained in:
parent
9c20e780d0
commit
4276964f4d
3 changed files with 25 additions and 22 deletions
|
@ -354,7 +354,7 @@ async fn should_reject_message_with_expired_token() -> TestResult {
|
|||
}
|
||||
|
||||
#[test_log::test(actix::test)]
|
||||
// NOTE: failed then passed on retry: count = 2
|
||||
// NOTE: failed then passed on retry: count = 3
|
||||
async fn should_send_validate_repo_when_retryable_error() -> TestResult {
|
||||
//given
|
||||
let fs = given::a_filesystem();
|
||||
|
|
|
@ -65,7 +65,6 @@ impl Handler<FileUpdated> for Server {
|
|||
impl Handler<ReceiveServerConfig> for Server {
|
||||
type Result = ();
|
||||
|
||||
#[allow(clippy::cognitive_complexity)] // TODO: (#75) reduce complexity
|
||||
fn handle(&mut self, msg: ReceiveServerConfig, _ctx: &mut Self::Context) -> Self::Result {
|
||||
let Ok(socket_addr) = msg.http() else {
|
||||
warn!("Unable to parse http.addr");
|
||||
|
@ -76,27 +75,9 @@ impl Handler<ReceiveServerConfig> for Server {
|
|||
}
|
||||
self.generation.inc();
|
||||
let server_config = msg;
|
||||
// Server Storage
|
||||
let dir = server_config.storage().path();
|
||||
if !dir.exists() {
|
||||
info!(?dir, "server storage doesn't exist - creating it");
|
||||
if let Err(err) = self.fs.dir_create(dir) {
|
||||
error!(?err, ?dir, "Failed to create server storage");
|
||||
return;
|
||||
}
|
||||
}
|
||||
let Ok(canon) = dir.canonicalize() else {
|
||||
error!(?dir, "Failed to confirm server storage");
|
||||
let Some(server_storage) = self.server_storage(&server_config) else {
|
||||
return;
|
||||
};
|
||||
info!(dir = ?canon, "server storage");
|
||||
|
||||
// Forge directories in Server Storage
|
||||
let server_storage = server_config.storage();
|
||||
if let Err(err) = self.create_forge_data_directories(&server_config, dir) {
|
||||
error!(?err, "Failure creating forge storage");
|
||||
return;
|
||||
}
|
||||
|
||||
// Webhook Server
|
||||
info!("Starting Webhook Server...");
|
||||
|
@ -247,4 +228,27 @@ impl Server {
|
|||
info!("Started");
|
||||
(repo_alias, addr)
|
||||
}
|
||||
|
||||
fn server_storage<'cfg>(
|
||||
&self,
|
||||
server_config: &'cfg ReceiveServerConfig,
|
||||
) -> Option<&'cfg ServerStorage> {
|
||||
let server_storage = server_config.storage();
|
||||
let dir = server_storage.path();
|
||||
if !dir.exists() {
|
||||
if let Err(err) = self.fs.dir_create(dir) {
|
||||
error!(?err, ?dir, "Failed to create server storage");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
let Ok(canon) = dir.canonicalize() else {
|
||||
error!(?dir, "Failed to confirm server storage");
|
||||
return None;
|
||||
};
|
||||
if let Err(err) = self.create_forge_data_directories(server_config, &canon) {
|
||||
error!(?err, "Failure creating forge storage");
|
||||
return None;
|
||||
}
|
||||
Some(server_storage)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ pub fn start(
|
|||
|
||||
info!("Starting Server...");
|
||||
let execution = async move {
|
||||
//-
|
||||
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
|
||||
server.do_send(FileUpdated);
|
||||
|
||||
|
|
Loading…
Reference in a new issue