mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-24 16:45:22 +02:00
- Introduced a new endpoint for cancelling deployments, allowing users to cancel both application and compose deployments. - Implemented validation schemas for cancellation requests. - Enhanced the deployment dashboard to provide a cancellation option for stuck deployments. - Updated server-side logic to handle cancellation requests and send appropriate events.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { findServerById } from "@dokploy/server";
|
|
import type { DeploymentJob } from "../queues/queue-types";
|
|
|
|
export const deploy = async (jobData: DeploymentJob) => {
|
|
try {
|
|
const server = await findServerById(jobData.serverId as string);
|
|
if (server.serverStatus === "inactive") {
|
|
throw new Error("Server is inactive");
|
|
}
|
|
|
|
const result = await fetch(`${process.env.SERVER_URL}/deploy`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-API-Key": process.env.API_KEY || "NO-DEFINED",
|
|
},
|
|
body: JSON.stringify(jobData),
|
|
});
|
|
|
|
const data = await result.json();
|
|
return data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
type CancelDeploymentData =
|
|
| { applicationId: string; applicationType: "application" }
|
|
| { composeId: string; applicationType: "compose" };
|
|
|
|
export const cancelDeployment = async (cancelData: CancelDeploymentData) => {
|
|
try {
|
|
const result = await fetch(`${process.env.SERVER_URL}/cancel-deployment`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-API-Key": process.env.API_KEY || "NO-DEFINED",
|
|
},
|
|
body: JSON.stringify(cancelData),
|
|
});
|
|
|
|
if (!result.ok) {
|
|
const errorData = await result.json().catch(() => ({}));
|
|
throw new Error(errorData.message || "Failed to cancel deployment");
|
|
}
|
|
|
|
const data = await result.json();
|
|
return data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|