fix(subscriptions): change const done to let and resolve with finally to allow while loop to exit

This commit is contained in:
Maks Pikov
2026-04-02 22:21:42 +00:00
parent c7b5e73d1c
commit 5978c4135e
6 changed files with 59 additions and 54 deletions

View File

@@ -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()!;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {