Skip to content

Commit

Permalink
feat: allow closing deployment in failed states as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ilbertt committed May 19, 2024
1 parent 21c0fad commit 8550fbc
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 75 deletions.
133 changes: 65 additions & 68 deletions frontend/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,75 +190,72 @@ export default function Dashboard() {
</CollapsibleContent>
</Collapsible>
</CardContent>
{!(
isDeploymentClosed(el.deployment) ||
isDeploymentFailed(el.deployment)
) && (
<CardFooter className="gap-2">
{isDeploymentActive(el.deployment) && (
<>
<Button
variant="secondary"
onClick={() => handleFetchStatus(el.deployment)}
>
Fetch status
</Button>
<Dialog
open={isStatusDialogOpen}
onOpenChange={setIsStatusDialogOpen}
{!isDeploymentClosed(el.deployment) && (
<CardFooter className="gap-2">
{(isDeploymentActive(el.deployment) && !isDeploymentFailed(el.deployment)) && (
<>
<Button
variant="secondary"
onClick={() => handleFetchStatus(el.deployment)}
>
Fetch status
</Button>
<Dialog
open={isStatusDialogOpen}
onOpenChange={setIsStatusDialogOpen}
>
<DialogContent>
<DialogHeader>
<DialogTitle>Deployment status</DialogTitle>
<DialogDescription>
{isFetchingStatus ? (
<Spinner />
) : (
Boolean(leaseStatusData) && (
<span className="font-mono">
{JSON.stringify(leaseStatusData, null, 2)}
</span>
)
)}
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
</>
)}
<Dialog
open={dialogDeploymentId === el.id}
onOpenChange={(open) =>
setDialogDeploymentId(open ? el.id : undefined)
}
>
<DialogTrigger asChild>
<Button variant="outline">Close Deployment</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
Deployment id to close:
<br />
<span className="font-mono text-nowrap">{el.id}</span>
<br />
<b>This action cannot be undone.</b>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<LoadingButton
variant="destructive"
onClick={() => handleCloseDeployment(el.id)}
isLoading={isClosingDeployment}
>
<DialogContent>
<DialogHeader>
<DialogTitle>Deployment status</DialogTitle>
<DialogDescription>
{isFetchingStatus ? (
<Spinner />
) : (
Boolean(leaseStatusData) && (
<span className="font-mono">
{JSON.stringify(leaseStatusData, null, 2)}
</span>
)
)}
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
</>
)}
<Dialog
open={dialogDeploymentId === el.id}
onOpenChange={(open) =>
setDialogDeploymentId(open ? el.id : undefined)
}
>
<DialogTrigger asChild>
<Button variant="outline">Close Deployment</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
Deployment id to close:
<br />
<span className="font-mono text-nowrap">{el.id}</span>
<br />
<b>This action cannot be undone.</b>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<LoadingButton
variant="destructive"
onClick={() => handleCloseDeployment(el.id)}
isLoading={isClosingDeployment}
>
Close Deployment
</LoadingButton>
</DialogFooter>
</DialogContent>
</Dialog>
</CardFooter>
)}
Close Deployment
</LoadingButton>
</DialogFooter>
</DialogContent>
</Dialog>
</CardFooter>
)}
</Card>
))}
</div>
Expand Down
42 changes: 35 additions & 7 deletions src/backend/src/api/services/deployments_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::{
};
use candid::Principal;

use super::{log_info, log_warn};

pub struct DeploymentsService {
deployments_memory: DeploymentsMemory,
}
Expand Down Expand Up @@ -63,9 +65,33 @@ impl DeploymentsService {
// either it fails while being creating deployment and lease (and thus there is no need to close it)
// or it eventually gets to the LeaseCreated or Active state (and from that point on it can be closed, updated or deposited being made to it)
match deployment_state {
DeploymentState::Active | DeploymentState::LeaseCreated { .. } => Ok(()),
_ => Err(ApiError::internal(&format!(
"Deployment is not active. Cannot close it now. Current state: {:?}",
DeploymentState::Initialized
| DeploymentState::DeploymentCreated { .. }
| DeploymentState::Active
| DeploymentState::LeaseCreated { .. } => {
log_info!(
format!(
"[Deployment {}]: Closing deployment in {:?} state",
deployment_id, deployment_state
),
"check_deployment_state"
);

Ok(())
}
DeploymentState::FailedOnCanister { .. } | DeploymentState::FailedOnClient { .. } => {
log_warn!(
format!(
"[Deployment {}]: Deployment is already in {:?} state",
deployment_id, deployment_state
),
"check_deployment_state"
);

Ok(())
}
DeploymentState::Closed => Err(ApiError::permission_denied(&format!(
"Cannot close deployment. Current state: {:?}",
deployment_state
))),
}
Expand All @@ -84,9 +110,7 @@ impl DeploymentsService {
reason: reason.clone(),
},
true,
)?;

Ok(())
)
}

pub fn get_akash_deployment_info(
Expand Down Expand Up @@ -126,7 +150,11 @@ impl DeploymentsService {
ApiError::not_found(&format!("Deployment {} not found", deployment_id))
})?;

if let DeploymentState::FailedOnCanister { .. } = deployment.state() {
// the deployment can still be closed if it failed on canister,
// it may just fail closing but we let this case pass
if matches!(deployment.state(), DeploymentState::FailedOnCanister { .. })
&& !matches!(deployment_update, DeploymentState::Closed)
{
return Err(ApiError::internal(&format!(
"Deployment {} already failed",
deployment_id
Expand Down

0 comments on commit 8550fbc

Please sign in to comment.