feat: add triggerType field to application schema for enhanced event handling

This commit is contained in:
Mauricio Siu
2026-02-24 18:35:26 -06:00
parent e92ba584c0
commit 2d0874d499
5 changed files with 35 additions and 27 deletions

View File

@@ -43,7 +43,6 @@ import {
restoreWebServerBackup,
} from "@dokploy/server/utils/restore";
import { TRPCError } from "@trpc/server";
import { observable } from "@trpc/server/observable";
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
import {
@@ -375,58 +374,59 @@ export const backupRouter = createTRPCRouter({
},
})
.input(apiRestoreBackup)
.subscription(async ({ input }) => {
.subscription(async function* ({ input, signal }) {
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);
return observable<string>((emit) => {
restorePostgresBackup(postgres, destination, input, (log) => {
emit.next(log);
});
restorePostgresBackup(postgres, destination, input, (log) => {
queue.push(log);
});
}
if (input.databaseType === "mysql") {
const mysql = await findMySqlById(input.databaseId);
return observable<string>((emit) => {
restoreMySqlBackup(mysql, destination, input, (log) => {
emit.next(log);
});
restoreMySqlBackup(mysql, destination, input, (log) => {
queue.push(log);
});
}
if (input.databaseType === "mariadb") {
const mariadb = await findMariadbById(input.databaseId);
return observable<string>((emit) => {
restoreMariadbBackup(mariadb, destination, input, (log) => {
emit.next(log);
});
restoreMariadbBackup(mariadb, destination, input, (log) => {
queue.push(log);
});
}
if (input.databaseType === "mongo") {
const mongo = await findMongoById(input.databaseId);
return observable<string>((emit) => {
restoreMongoBackup(mongo, destination, input, (log) => {
emit.next(log);
});
restoreMongoBackup(mongo, destination, input, (log) => {
queue.push(log);
});
}
if (input.databaseType === "web-server") {
return observable<string>((emit) => {
restoreWebServerBackup(destination, input.backupFile, (log) => {
emit.next(log);
});
restoreWebServerBackup(destination, input.backupFile, (log) => {
queue.push(log);
});
}
}
if (input.backupType === "compose") {
const compose = await findComposeById(input.databaseId);
return observable<string>((emit) => {
restoreComposeBackup(compose, destination, input, (log) => {
emit.next(log);
});
restoreComposeBackup(compose, destination, input, (log) => {
queue.push(log);
});
}
return true;
while (!done || queue.length > 0) {
if (queue.length > 0) {
yield queue.shift()!;
} else {
await new Promise((r) => setTimeout(r, 50));
}
if (signal?.aborted) {
return;
}
}
}),
});

View File

@@ -473,6 +473,7 @@ export const projectRouter = createTRPCRouter({
await createPreviewDeployment({
...rest,
applicationId: newApplication.applicationId,
domainId: undefined,
});
}