From 5978c4135e96e98d29a3f88d3be04908d9d2c5d5 Mon Sep 17 00:00:00 2001 From: Maks Pikov Date: Thu, 2 Apr 2026 22:21:42 +0000 Subject: [PATCH 1/2] fix(subscriptions): change const done to let and resolve with finally to allow while loop to exit --- apps/dokploy/server/api/routers/backup.ts | 73 ++++++++------------- apps/dokploy/server/api/routers/libsql.ts | 8 ++- apps/dokploy/server/api/routers/mongo.ts | 8 ++- apps/dokploy/server/api/routers/mysql.ts | 8 ++- apps/dokploy/server/api/routers/postgres.ts | 8 ++- apps/dokploy/server/api/routers/redis.ts | 8 ++- 6 files changed, 59 insertions(+), 54 deletions(-) diff --git a/apps/dokploy/server/api/routers/backup.ts b/apps/dokploy/server/api/routers/backup.ts index 6d358f631..98f8c658d 100644 --- a/apps/dokploy/server/api/routers/backup.ts +++ b/apps/dokploy/server/api/routers/backup.ts @@ -545,52 +545,37 @@ export const backupRouter = createTRPCRouter({ } const destination = await findDestinationById(input.destinationId); const queue: string[] = []; - const done = false; - if (input.backupType === "database") { - if (input.databaseType === "postgres") { - const postgres = await findPostgresById(input.databaseId); - - restorePostgresBackup(postgres, destination, input, (log) => { - queue.push(log); - }); + let done = false; + const onLog = (log: string) => queue.push(log); + (async () => { + if (input.backupType === "database") { + if (input.databaseType === "postgres") { + const postgres = await findPostgresById(input.databaseId); + await restorePostgresBackup(postgres, destination, input, onLog); + } else if (input.databaseType === "mysql") { + const mysql = await findMySqlById(input.databaseId); + await restoreMySqlBackup(mysql, destination, input, onLog); + } else if (input.databaseType === "mariadb") { + const mariadb = await findMariadbById(input.databaseId); + await restoreMariadbBackup(mariadb, destination, input, onLog); + } else if (input.databaseType === "mongo") { + const mongo = await findMongoById(input.databaseId); + await restoreMongoBackup(mongo, destination, input, onLog); + } else if (input.databaseType === "libsql") { + const libsql = await findLibsqlById(input.databaseId); + await restoreLibsqlBackup(libsql, destination, input, onLog); + } else if (input.databaseType === "web-server") { + await restoreWebServerBackup(destination, input.backupFile, onLog); + } + } else if (input.backupType === "compose") { + const compose = await findComposeById(input.databaseId); + await restoreComposeBackup(compose, destination, input, onLog); } - - if (input.databaseType === "mysql") { - const mysql = await findMySqlById(input.databaseId); - restoreMySqlBackup(mysql, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "mariadb") { - const mariadb = await findMariadbById(input.databaseId); - restoreMariadbBackup(mariadb, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "mongo") { - const mongo = await findMongoById(input.databaseId); - restoreMongoBackup(mongo, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "libsql") { - const libsql = await findLibsqlById(input.databaseId); - restoreLibsqlBackup(libsql, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "web-server") { - restoreWebServerBackup(destination, input.backupFile, (log) => { - queue.push(log); - }); - } - } - if (input.backupType === "compose") { - const compose = await findComposeById(input.databaseId); - restoreComposeBackup(compose, destination, input, (log) => { - queue.push(log); + })() + .catch(() => {}) + .finally(() => { + done = true; }); - } while (!done || queue.length > 0) { if (queue.length > 0) { yield queue.shift()!; diff --git a/apps/dokploy/server/api/routers/libsql.ts b/apps/dokploy/server/api/routers/libsql.ts index 614e42101..79dcc4443 100644 --- a/apps/dokploy/server/api/routers/libsql.ts +++ b/apps/dokploy/server/api/routers/libsql.ts @@ -246,11 +246,15 @@ export const libsqlRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployLibsql(input.libsqlId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/mongo.ts b/apps/dokploy/server/api/routers/mongo.ts index a64535e24..47c06f819 100644 --- a/apps/dokploy/server/api/routers/mongo.ts +++ b/apps/dokploy/server/api/routers/mongo.ts @@ -228,11 +228,15 @@ export const mongoRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployMongo(input.mongoId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/mysql.ts b/apps/dokploy/server/api/routers/mysql.ts index abb0f97a7..8e1938caa 100644 --- a/apps/dokploy/server/api/routers/mysql.ts +++ b/apps/dokploy/server/api/routers/mysql.ts @@ -230,11 +230,15 @@ export const mysqlRouter = createTRPCRouter({ }); const queue: string[] = []; - const done = false; + let done = false; deployMySql(input.mysqlId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index 3b3cfd208..b591726eb 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -233,11 +233,15 @@ export const postgresRouter = createTRPCRouter({ }); const queue: string[] = []; - const done = false; + let done = false; deployPostgres(input.postgresId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/redis.ts b/apps/dokploy/server/api/routers/redis.ts index 01d922aa4..dfd8e1a87 100644 --- a/apps/dokploy/server/api/routers/redis.ts +++ b/apps/dokploy/server/api/routers/redis.ts @@ -251,11 +251,15 @@ export const redisRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployRedis(input.redisId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { From df95766807fa2056a9fbae2ed3524e937d377ae8 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Fri, 3 Apr 2026 15:13:09 -0600 Subject: [PATCH 2/2] refactor(backup): rename async function for clarity and improve error logging - Changed the anonymous async function to a named function `runRestore` for better readability. - Enhanced error handling to log specific error messages during the restore process. --- apps/dokploy/server/api/routers/backup.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/dokploy/server/api/routers/backup.ts b/apps/dokploy/server/api/routers/backup.ts index 98f8c658d..ead1ef4b6 100644 --- a/apps/dokploy/server/api/routers/backup.ts +++ b/apps/dokploy/server/api/routers/backup.ts @@ -547,7 +547,7 @@ export const backupRouter = createTRPCRouter({ const queue: string[] = []; let done = false; const onLog = (log: string) => queue.push(log); - (async () => { + const runRestore = async () => { if (input.backupType === "database") { if (input.databaseType === "postgres") { const postgres = await findPostgresById(input.databaseId); @@ -571,8 +571,13 @@ export const backupRouter = createTRPCRouter({ const compose = await findComposeById(input.databaseId); await restoreComposeBackup(compose, destination, input, onLog); } - })() - .catch(() => {}) + }; + runRestore() + .catch((error) => { + onLog( + `Error: ${error instanceof Error ? error.message : String(error)}`, + ); + }) .finally(() => { done = true; });