diff --git a/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx b/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx index c1c319949..dd384e74f 100644 --- a/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx +++ b/apps/dokploy/components/dashboard/application/deployments/show-deployments.tsx @@ -81,22 +81,28 @@ export const ShowDeployments = ({ const [url, setUrl] = React.useState(""); - // Check for stuck deployments (more than 9 minutes) + // Check for stuck deployment (more than 9 minutes) - only for the most recent deployment const stuckDeployment = useMemo(() => { if (!isCloud || !deployments || deployments.length === 0) return null; const now = Date.now(); - const NINE_MINUTES = 8 * 60 * 1000; // 9 minutes in milliseconds + const NINE_MINUTES = 10 * 60 * 1000; // 9 minutes in milliseconds - return deployments.find((deployment) => { - if (deployment.status !== "running" || !deployment.startedAt) - return false; + // Get the most recent deployment (first in the list since they're sorted by date) + const mostRecentDeployment = deployments[0]; - const startTime = new Date(deployment.startedAt).getTime(); - const elapsed = now - startTime; + if ( + !mostRecentDeployment || + mostRecentDeployment.status !== "running" || + !mostRecentDeployment.startedAt + ) { + return null; + } - return elapsed > NINE_MINUTES; - }); + const startTime = new Date(mostRecentDeployment.startedAt).getTime(); + const elapsed = now - startTime; + + return elapsed > NINE_MINUTES ? mostRecentDeployment : null; }, [isCloud, deployments]); useEffect(() => { setUrl(document.location.origin); diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index dea6a7116..28094cfb9 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -24,6 +24,7 @@ import { unzipDrop, updateApplication, updateApplicationStatus, + updateDeploymentStatus, writeConfig, writeConfigRemote, // uploadFileSchema @@ -919,6 +920,14 @@ export const applicationRouter = createTRPCRouter({ if (IS_CLOUD && application.serverId) { try { await updateApplicationStatus(input.applicationId, "idle"); + + if (application.deployments[0]) { + await updateDeploymentStatus( + application.deployments[0].deploymentId, + "done", + ); + } + await cancelDeployment({ applicationId: input.applicationId, applicationType: "application", diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index ecd68c0ff..080bd917c 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -29,6 +29,7 @@ import { startCompose, stopCompose, updateCompose, + updateDeploymentStatus, } from "@dokploy/server"; import { type CompleteTemplate, @@ -953,6 +954,14 @@ export const composeRouter = createTRPCRouter({ await updateCompose(input.composeId, { composeStatus: "idle", }); + + if (compose.deployments[0]) { + await updateDeploymentStatus( + compose.deployments[0].deploymentId, + "done", + ); + } + await cancelDeployment({ composeId: input.composeId, applicationType: "compose",