refactor(controller): simplify start and restart methods by using reconciler
This commit is contained in:
@@ -105,28 +105,15 @@ impl Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(&self) -> Result<()> {
|
pub async fn start(&self) -> Result<()> {
|
||||||
let instance = self.ctx.require_instance()?;
|
|
||||||
let project = self.ctx.require_project()?;
|
let project = self.ctx.require_project()?;
|
||||||
|
let reconciler = Reconciler { ctx: &self.ctx };
|
||||||
if self
|
|
||||||
.ctx
|
|
||||||
.docker
|
|
||||||
.is_container_running_by_id(&instance.container_id)
|
|
||||||
.await?
|
|
||||||
{
|
|
||||||
println!("{}", "Container is already running".yellow());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{}", "Starting container...".cyan());
|
println!("{}", "Starting container...".cyan());
|
||||||
self.ctx
|
reconciler.reconcile(project).await?;
|
||||||
.docker
|
|
||||||
.start_container_by_id(&instance.container_id)
|
|
||||||
.await?;
|
|
||||||
println!(
|
println!(
|
||||||
"{} {} {}",
|
"{} {} {}",
|
||||||
"✓".green().bold(),
|
"✓".green().bold(),
|
||||||
"Container".green(),
|
"Container started".green(),
|
||||||
project.container_name().yellow()
|
project.container_name().yellow()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -163,14 +150,11 @@ impl Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn restart(&self) -> Result<()> {
|
pub async fn restart(&self) -> Result<()> {
|
||||||
let instance = self.ctx.require_instance()?;
|
|
||||||
let project = self.ctx.require_project()?;
|
let project = self.ctx.require_project()?;
|
||||||
|
let reconciler = Reconciler { ctx: &self.ctx };
|
||||||
|
|
||||||
println!("{}", "Restarting container...".cyan());
|
println!("{}", "Restarting container...".cyan());
|
||||||
self.ctx
|
reconciler.reconcile(project).await?;
|
||||||
.docker
|
|
||||||
.restart_container(&instance.container_id, 10)
|
|
||||||
.await?;
|
|
||||||
println!(
|
println!(
|
||||||
"{} {} {}",
|
"{} {} {}",
|
||||||
"✓".green().bold(),
|
"✓".green().bold(),
|
||||||
|
|||||||
Reference in New Issue
Block a user