refactor: remove manual log deletion from clearOldDeployments

This commit is contained in:
irwanda 2026-06-07 08:57:20 +07:00
parent 74843662e0
commit 18d2884469
3 changed files with 3 additions and 17 deletions

View File

@ -754,7 +754,7 @@ export const applicationRouter = createTRPCRouter({
deployment: ["create"],
});
const application = await findApplicationById(input.applicationId);
await clearOldDeployments(application.applicationId, "application", application.serverId);
await clearOldDeployments(application.applicationId, "application");
await audit(ctx, {
action: "delete",
resourceType: "application",

View File

@ -298,7 +298,7 @@ export const composeRouter = createTRPCRouter({
deployment: ["create"],
});
const compose = await findComposeById(input.composeId);
await clearOldDeployments(compose.composeId, "compose", compose.serverId);
await clearOldDeployments(compose.composeId, "compose");
await audit(ctx, {
action: "update",
resourceType: "compose",

View File

@ -1036,8 +1036,7 @@ export const findAllDeploymentsByServerId = async (serverId: string) => {
export const clearOldDeployments = async (
id: string,
type: "application" | "compose",
serverId: string | null,
type: "application" | "compose"
) => {
const deploymentsList = await db.query.deployments.findMany({
where: eq(deployments[`${type}Id`], id),
@ -1055,21 +1054,12 @@ export const clearOldDeployments = async (
(d) => d.deploymentId !== currentDeployment.deploymentId,
);
const remoteLogCommands: string[] = [];
for (const oldDeployment of deploymentsToDelete) {
try {
if (oldDeployment.rollbackId) {
await removeRollbackById(oldDeployment.rollbackId);
}
const logPath = path.join(oldDeployment.logPath);
const hasLogPath = logPath && logPath !== ".";
if (serverId) {
if (hasLogPath) remoteLogCommands.push(`rm -f "${logPath}"`);
}
await removeDeployment(oldDeployment.deploymentId);
} catch (err) {
console.error(
@ -1078,8 +1068,4 @@ export const clearOldDeployments = async (
);
}
}
if (serverId && remoteLogCommands.length > 0) {
await execAsyncRemote(serverId, remoteLogCommands.join(";"));
}
};