From 4c3bc8efdc5a6ba90a095c1cab63c6b326073ec3 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:49:21 -0600 Subject: [PATCH] refactor(deployment): set status error when application or compose have troubles when creating deployment log --- .../dokploy/server/api/services/deployment.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/dokploy/server/api/services/deployment.ts b/apps/dokploy/server/api/services/deployment.ts index c13047b5..5ea39c57 100644 --- a/apps/dokploy/server/api/services/deployment.ts +++ b/apps/dokploy/server/api/services/deployment.ts @@ -12,8 +12,12 @@ import { removeDirectoryIfExistsContent } from "@/server/utils/filesystem/direct import { TRPCError } from "@trpc/server"; import { format } from "date-fns"; import { desc, eq } from "drizzle-orm"; -import { type Application, findApplicationById } from "./application"; -import { type Compose, findComposeById } from "./compose"; +import { + type Application, + findApplicationById, + updateApplicationStatus, +} from "./application"; +import { type Compose, findComposeById, updateCompose } from "./compose"; import { type Server, findServerById } from "./server"; import { execAsyncRemote } from "@/server/utils/process/execAsync"; @@ -42,9 +46,9 @@ export const createDeployment = async ( "deploymentId" | "createdAt" | "status" | "logPath" >, ) => { - try { - const application = await findApplicationById(deployment.applicationId); + const application = await findApplicationById(deployment.applicationId); + try { // await removeLastTenDeployments(deployment.applicationId); const { LOGS_PATH } = paths(!!application.serverId); const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss"); @@ -85,6 +89,7 @@ export const createDeployment = async ( } return deploymentCreate[0]; } catch (error) { + await updateApplicationStatus(application.applicationId, "error"); console.log(error); throw new TRPCError({ code: "BAD_REQUEST", @@ -99,9 +104,8 @@ export const createDeploymentCompose = async ( "deploymentId" | "createdAt" | "status" | "logPath" >, ) => { + const compose = await findComposeById(deployment.composeId); try { - const compose = await findComposeById(deployment.composeId); - // await removeLastTenComposeDeployments(deployment.composeId); const { LOGS_PATH } = paths(!!compose.serverId); const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss"); @@ -142,6 +146,9 @@ echo "Initializing deployment" >> ${logFilePath}; } return deploymentCreate[0]; } catch (error) { + await updateCompose(compose.composeId, { + composeStatus: "error", + }); console.log(error); throw new TRPCError({ code: "BAD_REQUEST",