refactor: split server storage creation out from startup
Some checks failed
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Failing after 22s

Closes kemitix/git-next#75
This commit is contained in:
Paul Campbell 2024-07-11 07:27:11 +01:00
parent 9c20e780d0
commit b9bbe06d90
2 changed files with 24 additions and 21 deletions

View file

@ -65,7 +65,6 @@ impl Handler<FileUpdated> for Server {
impl Handler<ReceiveServerConfig> for Server { impl Handler<ReceiveServerConfig> for Server {
type Result = (); type Result = ();
#[allow(clippy::cognitive_complexity)] // TODO: (#75) reduce complexity
fn handle(&mut self, msg: ReceiveServerConfig, _ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: ReceiveServerConfig, _ctx: &mut Self::Context) -> Self::Result {
let Ok(socket_addr) = msg.http() else { let Ok(socket_addr) = msg.http() else {
warn!("Unable to parse http.addr"); warn!("Unable to parse http.addr");
@ -76,27 +75,9 @@ impl Handler<ReceiveServerConfig> for Server {
} }
self.generation.inc(); self.generation.inc();
let server_config = msg; let server_config = msg;
// Server Storage let Some(server_storage) = self.server_storage(&server_config) else {
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");
return; 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 // Webhook Server
info!("Starting Webhook Server..."); info!("Starting Webhook Server...");
@ -247,4 +228,27 @@ impl Server {
info!("Started"); info!("Started");
(repo_alias, addr) (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)
}
} }

View file

@ -40,7 +40,6 @@ pub fn start(
info!("Starting Server..."); info!("Starting Server...");
let execution = async move { let execution = async move {
//-
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start(); let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated); server.do_send(FileUpdated);