feat(deployment): improve stuck deployment detection and update status

- Enhanced the stuck deployment check to only consider the most recent deployment.
- Updated the logic to correctly identify if the most recent deployment has been running for more than 9 minutes.
- Added functionality to update the deployment status to "done" upon application and compose cancellation.
This commit is contained in:
Mauricio Siu
2025-09-06 22:05:39 -06:00
parent 4e69c70697
commit 766cd20e90
3 changed files with 33 additions and 9 deletions
@@ -81,22 +81,28 @@ export const ShowDeployments = ({
const [url, setUrl] = React.useState(""); 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(() => { const stuckDeployment = useMemo(() => {
if (!isCloud || !deployments || deployments.length === 0) return null; if (!isCloud || !deployments || deployments.length === 0) return null;
const now = Date.now(); 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) => { // Get the most recent deployment (first in the list since they're sorted by date)
if (deployment.status !== "running" || !deployment.startedAt) const mostRecentDeployment = deployments[0];
return false;
const startTime = new Date(deployment.startedAt).getTime(); if (
const elapsed = now - startTime; !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]); }, [isCloud, deployments]);
useEffect(() => { useEffect(() => {
setUrl(document.location.origin); setUrl(document.location.origin);
@@ -24,6 +24,7 @@ import {
unzipDrop, unzipDrop,
updateApplication, updateApplication,
updateApplicationStatus, updateApplicationStatus,
updateDeploymentStatus,
writeConfig, writeConfig,
writeConfigRemote, writeConfigRemote,
// uploadFileSchema // uploadFileSchema
@@ -919,6 +920,14 @@ export const applicationRouter = createTRPCRouter({
if (IS_CLOUD && application.serverId) { if (IS_CLOUD && application.serverId) {
try { try {
await updateApplicationStatus(input.applicationId, "idle"); await updateApplicationStatus(input.applicationId, "idle");
if (application.deployments[0]) {
await updateDeploymentStatus(
application.deployments[0].deploymentId,
"done",
);
}
await cancelDeployment({ await cancelDeployment({
applicationId: input.applicationId, applicationId: input.applicationId,
applicationType: "application", applicationType: "application",
@@ -29,6 +29,7 @@ import {
startCompose, startCompose,
stopCompose, stopCompose,
updateCompose, updateCompose,
updateDeploymentStatus,
} from "@dokploy/server"; } from "@dokploy/server";
import { import {
type CompleteTemplate, type CompleteTemplate,
@@ -953,6 +954,14 @@ export const composeRouter = createTRPCRouter({
await updateCompose(input.composeId, { await updateCompose(input.composeId, {
composeStatus: "idle", composeStatus: "idle",
}); });
if (compose.deployments[0]) {
await updateDeploymentStatus(
compose.deployments[0].deploymentId,
"done",
);
}
await cancelDeployment({ await cancelDeployment({
composeId: input.composeId, composeId: input.composeId,
applicationType: "compose", applicationType: "compose",