Skip to content

Commit 70418dd

Browse files
authored
Merge pull request #4128 from mixelburg/fix/subscription-done-flag
fix(subscriptions): set done=true when deployment/restore completes so the while loop can exit
2 parents e5aae15 + df95766 commit 70418dd

6 files changed

Lines changed: 64 additions & 54 deletions

File tree

apps/dokploy/server/api/routers/backup.ts

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -545,52 +545,42 @@ export const backupRouter = createTRPCRouter({
545545
}
546546
const destination = await findDestinationById(input.destinationId);
547547
const queue: string[] = [];
548-
const done = false;
549-
if (input.backupType === "database") {
550-
if (input.databaseType === "postgres") {
551-
const postgres = await findPostgresById(input.databaseId);
552-
553-
restorePostgresBackup(postgres, destination, input, (log) => {
554-
queue.push(log);
555-
});
556-
}
557-
558-
if (input.databaseType === "mysql") {
559-
const mysql = await findMySqlById(input.databaseId);
560-
restoreMySqlBackup(mysql, destination, input, (log) => {
561-
queue.push(log);
562-
});
563-
}
564-
if (input.databaseType === "mariadb") {
565-
const mariadb = await findMariadbById(input.databaseId);
566-
restoreMariadbBackup(mariadb, destination, input, (log) => {
567-
queue.push(log);
568-
});
569-
}
570-
if (input.databaseType === "mongo") {
571-
const mongo = await findMongoById(input.databaseId);
572-
restoreMongoBackup(mongo, destination, input, (log) => {
573-
queue.push(log);
574-
});
575-
}
576-
if (input.databaseType === "libsql") {
577-
const libsql = await findLibsqlById(input.databaseId);
578-
restoreLibsqlBackup(libsql, destination, input, (log) => {
579-
queue.push(log);
580-
});
581-
}
582-
if (input.databaseType === "web-server") {
583-
restoreWebServerBackup(destination, input.backupFile, (log) => {
584-
queue.push(log);
585-
});
548+
let done = false;
549+
const onLog = (log: string) => queue.push(log);
550+
const runRestore = async () => {
551+
if (input.backupType === "database") {
552+
if (input.databaseType === "postgres") {
553+
const postgres = await findPostgresById(input.databaseId);
554+
await restorePostgresBackup(postgres, destination, input, onLog);
555+
} else if (input.databaseType === "mysql") {
556+
const mysql = await findMySqlById(input.databaseId);
557+
await restoreMySqlBackup(mysql, destination, input, onLog);
558+
} else if (input.databaseType === "mariadb") {
559+
const mariadb = await findMariadbById(input.databaseId);
560+
await restoreMariadbBackup(mariadb, destination, input, onLog);
561+
} else if (input.databaseType === "mongo") {
562+
const mongo = await findMongoById(input.databaseId);
563+
await restoreMongoBackup(mongo, destination, input, onLog);
564+
} else if (input.databaseType === "libsql") {
565+
const libsql = await findLibsqlById(input.databaseId);
566+
await restoreLibsqlBackup(libsql, destination, input, onLog);
567+
} else if (input.databaseType === "web-server") {
568+
await restoreWebServerBackup(destination, input.backupFile, onLog);
569+
}
570+
} else if (input.backupType === "compose") {
571+
const compose = await findComposeById(input.databaseId);
572+
await restoreComposeBackup(compose, destination, input, onLog);
586573
}
587-
}
588-
if (input.backupType === "compose") {
589-
const compose = await findComposeById(input.databaseId);
590-
restoreComposeBackup(compose, destination, input, (log) => {
591-
queue.push(log);
574+
};
575+
runRestore()
576+
.catch((error) => {
577+
onLog(
578+
`Error: ${error instanceof Error ? error.message : String(error)}`,
579+
);
580+
})
581+
.finally(() => {
582+
done = true;
592583
});
593-
}
594584
while (!done || queue.length > 0) {
595585
if (queue.length > 0) {
596586
yield queue.shift()!;

apps/dokploy/server/api/routers/libsql.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,15 @@ export const libsqlRouter = createTRPCRouter({
246246
deployment: ["create"],
247247
});
248248
const queue: string[] = [];
249-
const done = false;
249+
let done = false;
250250

251251
deployLibsql(input.libsqlId, (log) => {
252252
queue.push(log);
253-
});
253+
})
254+
.catch(() => {})
255+
.finally(() => {
256+
done = true;
257+
});
254258

255259
while (!done || queue.length > 0) {
256260
if (queue.length > 0) {

apps/dokploy/server/api/routers/mongo.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,15 @@ export const mongoRouter = createTRPCRouter({
228228
deployment: ["create"],
229229
});
230230
const queue: string[] = [];
231-
const done = false;
231+
let done = false;
232232

233233
deployMongo(input.mongoId, (log) => {
234234
queue.push(log);
235-
});
235+
})
236+
.catch(() => {})
237+
.finally(() => {
238+
done = true;
239+
});
236240

237241
while (!done || queue.length > 0) {
238242
if (queue.length > 0) {

apps/dokploy/server/api/routers/mysql.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,15 @@ export const mysqlRouter = createTRPCRouter({
230230
});
231231

232232
const queue: string[] = [];
233-
const done = false;
233+
let done = false;
234234

235235
deployMySql(input.mysqlId, (log) => {
236236
queue.push(log);
237-
});
237+
})
238+
.catch(() => {})
239+
.finally(() => {
240+
done = true;
241+
});
238242

239243
while (!done || queue.length > 0) {
240244
if (queue.length > 0) {

apps/dokploy/server/api/routers/postgres.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,15 @@ export const postgresRouter = createTRPCRouter({
233233
});
234234

235235
const queue: string[] = [];
236-
const done = false;
236+
let done = false;
237237

238238
deployPostgres(input.postgresId, (log) => {
239239
queue.push(log);
240-
});
240+
})
241+
.catch(() => {})
242+
.finally(() => {
243+
done = true;
244+
});
241245

242246
while (!done || queue.length > 0) {
243247
if (queue.length > 0) {

apps/dokploy/server/api/routers/redis.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,15 @@ export const redisRouter = createTRPCRouter({
251251
deployment: ["create"],
252252
});
253253
const queue: string[] = [];
254-
const done = false;
254+
let done = false;
255255

256256
deployRedis(input.redisId, (log) => {
257257
queue.push(log);
258-
});
258+
})
259+
.catch(() => {})
260+
.finally(() => {
261+
done = true;
262+
});
259263

260264
while (!done || queue.length > 0) {
261265
if (queue.length > 0) {

0 commit comments

Comments
 (0)