Files
dokploy/packages/server/src/utils/startup/cancel-deployments.ts
Mauricio Siu 25006f7fe7 refactor: enhance deployment cancellation logic and improve Railpack build isolation
- Reintroduced the `initCancelDeployments` function in the server initialization sequence to ensure deployments can be canceled effectively.
- Updated the Railpack build command to use a unique builder name for each build, preventing conflicts during concurrent deployments.
- Enhanced the cancellation logic to reset application and compose statuses to "idle" after canceling running deployments, improving system reliability.
2026-06-16 06:59:10 -06:00

52 lines
1.2 KiB
TypeScript

import { applications, compose, deployments } from "@dokploy/server/db/schema";
import { eq, inArray } from "drizzle-orm";
import { db } from "../../db/index";
export const initCancelDeployments = async () => {
try {
console.log("Setting up cancel deployments....");
const result = await db
.update(deployments)
.set({
status: "cancelled",
})
.where(eq(deployments.status, "running"))
.returning();
// Reset the related services so they don't stay stuck in "running".
const applicationIds = [
...new Set(
result
.map((deployment) => deployment.applicationId)
.filter((id): id is string => !!id),
),
];
const composeIds = [
...new Set(
result
.map((deployment) => deployment.composeId)
.filter((id): id is string => !!id),
),
];
if (applicationIds.length > 0) {
await db
.update(applications)
.set({ applicationStatus: "idle" })
.where(inArray(applications.applicationId, applicationIds));
}
if (composeIds.length > 0) {
await db
.update(compose)
.set({ composeStatus: "idle" })
.where(inArray(compose.composeId, composeIds));
}
console.log(`Cancelled ${result.length} deployments`);
} catch (error) {
console.error(error);
}
};