A focused Docker Compose management web application.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: use pointers for actions

Brooke e3f1a0b9 f3aec331

+23 -27
+6 -6
packages/node/src/api/actions.rs packages/node/src/api/action.rs
··· 11 11 pub async fn restart_project(project: PathParam<String>, depot: &mut Depot) -> LuminaryResponse<()> { 12 12 let engine = obtain!(depot, LuminaryEngine); 13 13 14 - engine.restart(project.into_inner(), None).await?; 14 + engine.restart(&project.into_inner(), None).await?; 15 15 return Ok(().into()); 16 16 } 17 17 ··· 25 25 let engine = obtain!(depot, LuminaryEngine); 26 26 27 27 engine 28 - .restart(project.into_inner(), Some(service.into_inner())) 28 + .restart(&project.into_inner(), Some(&service.into_inner())) 29 29 .await?; 30 30 return Ok(().into()); 31 31 } ··· 35 35 pub async fn start_project(project: PathParam<String>, depot: &mut Depot) -> LuminaryResponse<()> { 36 36 let engine = obtain!(depot, LuminaryEngine); 37 37 38 - engine.start(project.into_inner(), None).await?; 38 + engine.start(&project.into_inner(), None).await?; 39 39 return Ok(().into()); 40 40 } 41 41 ··· 49 49 let engine = obtain!(depot, LuminaryEngine); 50 50 51 51 engine 52 - .start(project.into_inner(), Some(service.into_inner())) 52 + .start(&project.into_inner(), Some(&service.into_inner())) 53 53 .await?; 54 54 return Ok(().into()); 55 55 } ··· 59 59 pub async fn stop_project(project: PathParam<String>, depot: &mut Depot) -> LuminaryResponse<()> { 60 60 let engine = obtain!(depot, LuminaryEngine); 61 61 62 - engine.stop(project.into_inner(), None).await?; 62 + engine.stop(&project.into_inner(), None).await?; 63 63 return Ok(().into()); 64 64 } 65 65 ··· 73 73 let engine = obtain!(depot, LuminaryEngine); 74 74 75 75 engine 76 - .stop(project.into_inner(), Some(service.into_inner())) 76 + .stop(&project.into_inner(), Some(&service.into_inner())) 77 77 .await?; 78 78 return Ok(().into()); 79 79 }
+7 -7
packages/node/src/api/mod.rs
··· 14 14 logging::BroadcastLayer, 15 15 }; 16 16 17 - mod actions; 17 + mod action; 18 18 mod auth; 19 19 pub mod realtime; 20 20 mod response; ··· 71 71 .push( 72 72 Router::with_path("/project/{project}") 73 73 .push(Router::with_path("logs").get(logs_subscribe)) 74 - .push(Router::with_path("restart").post(actions::restart_project)) 75 - .push(Router::with_path("start").post(actions::start_project)) 76 - .push(Router::with_path("stop").post(actions::stop_project)) 74 + .push(Router::with_path("restart").post(action::restart_project)) 75 + .push(Router::with_path("start").post(action::start_project)) 76 + .push(Router::with_path("stop").post(action::stop_project)) 77 77 .push( 78 78 Router::with_path("service/{service}") 79 - .push(Router::with_path("restart").post(actions::restart_service)) 80 - .push(Router::with_path("start").post(actions::start_service)) 81 - .push(Router::with_path("stop").post(actions::stop_service)), 79 + .push(Router::with_path("restart").post(action::restart_service)) 80 + .push(Router::with_path("start").post(action::start_service)) 81 + .push(Router::with_path("stop").post(action::stop_service)), 82 82 ), 83 83 ), 84 84 ),
+9 -14
packages/node/src/core/action.rs
··· 7 7 impl LuminaryEngine { 8 8 /// Updates the currently processing action for the given project and optionally, a specific service within that project. 9 9 #[wrap_err("Failed to set action for service")] 10 - async fn set_action( 11 - &self, 12 - project: String, 13 - service: Option<String>, 14 - action: LuminaryAction, 15 - ) -> Result<()> { 10 + async fn set_action(&self, project: &str, service: Option<&str>, action: LuminaryAction) -> Result<()> { 16 11 // Get list of targets to update 17 12 let mut project_list = self.state.write().await; 18 - let targets = match project_list.0.get_mut(&project) { 13 + let targets = match project_list.0.get_mut(project) { 19 14 None => bail!("Unknown project '{}'", project), 20 15 Some(service_list) => match service { 21 16 None => service_list.services.0.values_mut().collect(), ··· 23 18 service_list 24 19 .services 25 20 .0 26 - .get_mut(&service) 21 + .get_mut(service) 27 22 .wrap_err_with(|| format!("Unknown service '{}' in '{}'", service, project))?, 28 23 ], 29 24 }, ··· 52 47 async fn run( 53 48 &self, 54 49 action: LuminaryAction, 55 - project: String, 56 - service: Option<String>, 50 + project: &str, 51 + service: Option<&str>, 57 52 mut args: Vec<&str>, 58 53 ) -> Result<()> { 59 - self.set_action(project.clone(), service.clone(), action).await?; 54 + self.set_action(project, service, action).await?; 60 55 61 56 if let Some(service) = &service { 62 57 args.push(service); ··· 70 65 71 66 /// Restarts the given project and optionally, a specific service within that project. 72 67 #[wrap_err("Failed to restart project/service")] 73 - pub async fn restart(&self, project: String, service: Option<String>) -> Result<()> { 68 + pub async fn restart(&self, project: &str, service: Option<&str>) -> Result<()> { 74 69 self.run(LuminaryAction::Restarting, project, service, vec!["restart"]) 75 70 .await?; 76 71 Ok(()) ··· 78 73 79 74 /// Starts the given project and optionally, a specific service within that project. 80 75 #[wrap_err("Failed to start project/service")] 81 - pub async fn start(&self, project: String, service: Option<String>) -> Result<()> { 76 + pub async fn start(&self, project: &str, service: Option<&str>) -> Result<()> { 82 77 self.run(LuminaryAction::Starting, project, service, vec!["up", "-d"]) 83 78 .await?; 84 79 Ok(()) ··· 86 81 87 82 /// Stops the given project and optionally, a specific service within that project. 88 83 #[wrap_err("Failed to stop project/service")] 89 - pub async fn stop(&self, project: String, service: Option<String>) -> Result<()> { 84 + pub async fn stop(&self, project: &str, service: Option<&str>) -> Result<()> { 90 85 self.run(LuminaryAction::Stopping, project, service, vec!["down"]) 91 86 .await?; 92 87 Ok(())
+1
packages/node/src/core/model.rs
··· 161 161 Restarting, 162 162 Stopping, 163 163 Starting, 164 + Pulling, 164 165 } 165 166 166 167 /// Stores the log channel and buffer for a project.