diff --git a/node/src/manager/commands/deployment/pause.rs b/node/src/manager/commands/deployment/pause.rs index 1cd4808fad8..2a690ea688a 100644 --- a/node/src/manager/commands/deployment/pause.rs +++ b/node/src/manager/commands/deployment/pause.rs @@ -3,8 +3,9 @@ use std::sync::Arc; use anyhow::Result; use graph_store_postgres::connection_pool::ConnectionPool; use graph_store_postgres::NotificationSender; -use graphman::commands::deployment::pause::load_active_deployment; -use graphman::commands::deployment::pause::pause_active_deployment; +use graphman::commands::deployment::pause::{ + load_active_deployment, pause_active_deployment, PauseDeploymentError, +}; use graphman::deployment::DeploymentSelector; pub fn run( @@ -12,11 +13,22 @@ pub fn run( notification_sender: Arc, deployment: DeploymentSelector, ) -> Result<()> { - let active_deployment = load_active_deployment(primary_pool.clone(), &deployment)?; + let active_deployment = load_active_deployment(primary_pool.clone(), &deployment); - println!("Pausing deployment {} ...", active_deployment.locator()); - - pause_active_deployment(primary_pool, notification_sender, active_deployment)?; + match active_deployment { + Ok(active_deployment) => { + println!("Pausing deployment {} ...", active_deployment.locator()); + pause_active_deployment(primary_pool, notification_sender, active_deployment)?; + } + Err(PauseDeploymentError::AlreadyPaused(locator)) => { + println!("Deployment {} is already paused", locator); + return Ok(()); + } + Err(PauseDeploymentError::Common(e)) => { + println!("Failed to load active deployment: {}", e); + return Err(e.into()); + } + } Ok(()) } diff --git a/server/graphman/src/resolvers/deployment_mutation/pause.rs b/server/graphman/src/resolvers/deployment_mutation/pause.rs index 8ba1f73446b..c16c505c178 100644 --- a/server/graphman/src/resolvers/deployment_mutation/pause.rs +++ b/server/graphman/src/resolvers/deployment_mutation/pause.rs @@ -1,18 +1,29 @@ use async_graphql::Result; -use graphman::commands::deployment::pause::load_active_deployment; -use graphman::commands::deployment::pause::pause_active_deployment; +use graphman::commands::deployment::pause::{ + load_active_deployment, pause_active_deployment, PauseDeploymentError, +}; use graphman::deployment::DeploymentSelector; use crate::resolvers::context::GraphmanContext; pub fn run(ctx: &GraphmanContext, deployment: &DeploymentSelector) -> Result<()> { - let active_deployment = load_active_deployment(ctx.primary_pool.clone(), deployment)?; + let active_deployment = load_active_deployment(ctx.primary_pool.clone(), deployment); - pause_active_deployment( - ctx.primary_pool.clone(), - ctx.notification_sender.clone(), - active_deployment, - )?; + match active_deployment { + Ok(active_deployment) => { + pause_active_deployment( + ctx.primary_pool.clone(), + ctx.notification_sender.clone(), + active_deployment, + )?; + } + Err(PauseDeploymentError::AlreadyPaused(_)) => { + return Ok(()); + } + Err(PauseDeploymentError::Common(e)) => { + return Err(e.into()); + } + } Ok(()) }