feat: add workflow run origin

This commit is contained in:
BennyKok
2023-12-19 12:30:52 +08:00
parent 39dd760ba0
commit 8f67a136c3
6 changed files with 659 additions and 17 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ export function RunWorkflowButton({
try {
const origin = window.location.origin;
await callServerPromise(
createRun(origin, workflow_version_id, machine)
createRun(origin, workflow_version_id, machine, undefined, true)
);
// console.log(res.json());
setIsLoading(false);
+6
View File
@@ -94,6 +94,11 @@ export const deploymentEnvironment = pgEnum("deployment_environment", [
"production",
]);
export const workflowRunOrigin = pgEnum("workflow_run_origin", [
"manual",
"api",
]);
// We still want to keep the workflow run record.
export const workflowRunsTable = dbSchema.table("workflow_runs", {
id: uuid("id").primaryKey().defaultRandom().notNull(),
@@ -114,6 +119,7 @@ export const workflowRunsTable = dbSchema.table("workflow_runs", {
machine_id: uuid("machine_id").references(() => machinesTable.id, {
onDelete: "set null",
}),
origin: workflowRunOrigin("origin").notNull().default("api"),
status: workflowRunStatus("status").notNull().default("not-started"),
ended_at: timestamp("ended_at"),
created_at: timestamp("created_at").defaultNow().notNull(),
+3 -16
View File
@@ -14,6 +14,7 @@ export const createRun = withServerPromise(
workflow_version_id: string,
machine_id: string,
inputs?: Record<string, string>,
isManualRun?: boolean,
) => {
const machine = await db.query.machinesTable.findFirst({
where: eq(workflowRunsTable.id, machine_id),
@@ -21,30 +22,15 @@ export const createRun = withServerPromise(
if (!machine) {
throw new Error("Machine not found");
// return new Response("Machine not found", {
// status: 404,
// });
}
const workflow_version_data =
// workflow_version_id
// ?
await db.query.workflowVersionTable.findFirst({
where: eq(workflowRunsTable.id, workflow_version_id),
});
// : workflow_version != undefined
// ? await db.query.workflowVersionTable.findFirst({
// where: and(
// eq(workflowVersionTable.version, workflow_version),
// eq(workflowVersionTable.workflow_id)
// ),
// })
// : null;
if (!workflow_version_data) {
throw new Error("Workflow version not found");
// return new Response("Workflow version not found", {
// status: 404,
// });
}
const comfyui_endpoint = `${machine.endpoint}/comfyui-deploy/run`;
@@ -93,6 +79,7 @@ export const createRun = withServerPromise(
workflow_version_id: workflow_version_data.id,
workflow_inputs: inputs,
machine_id,
origin: isManualRun ? "manual" : "api"
})
.returning();