feat: add timeout and run_log

This commit is contained in:
bennykok
2024-01-30 21:42:30 +08:00
parent 2193dd287d
commit b0d1bcc303
11 changed files with 1506 additions and 78 deletions
+2
View File
@@ -0,0 +1,2 @@
ALTER TYPE "workflow_run_status" ADD VALUE 'timeout';--> statement-breakpoint
ALTER TABLE "comfyui_deploy"."workflow_runs" ADD COLUMN "run_log" text;
File diff suppressed because it is too large Load Diff
+7
View File
@@ -337,6 +337,13 @@
"when": 1706384528895,
"tag": "0047_gifted_starbolt",
"breakpoints": true
},
{
"idx": 48,
"version": "5",
"when": 1706600255919,
"tag": "0048_dear_korath",
"breakpoints": true
}
]
}
+17 -9
View File
@@ -2,10 +2,8 @@ import { parseDataSafe } from "../../../../lib/parseDataSafe";
import { db } from "@/db/db";
import {
WorkflowRunStatusSchema,
userUsageTable,
workflowRunOutputs,
workflowRunsTable,
workflowTable,
} from "@/db/schema";
import { getCurrentPlan } from "@/server/getCurrentPlan";
import { stripe } from "@/server/stripe";
@@ -18,6 +16,7 @@ const Request = z.object({
status: WorkflowRunStatusSchema.optional(),
time: z.coerce.date().optional(),
output_data: z.any().optional(),
log_data: z.string().optional(),
});
export async function POST(request: Request) {
@@ -26,7 +25,17 @@ export async function POST(request: Request) {
if (!data || error) return error;
const { run_id, status, time, output_data } = data;
const { run_id, status, time, output_data, log_data } = data;
if (log_data) {
// It successfully started, update the started_at time
await db
.update(workflowRunsTable)
.set({
run_log: log_data,
})
.where(eq(workflowRunsTable.id, run_id));
}
if (status == "started" && time != undefined) {
// It successfully started, update the started_at time
@@ -48,6 +57,9 @@ export async function POST(request: Request) {
.where(eq(workflowRunsTable.id, run_id));
}
const ended =
status === "success" || status === "failed" || status === "timeout";
if (output_data) {
const workflow_run_output = await db.insert(workflowRunOutputs).values({
run_id: run_id,
@@ -58,8 +70,7 @@ export async function POST(request: Request) {
.update(workflowRunsTable)
.set({
status: status,
ended_at:
status === "success" || status === "failed" ? new Date() : null,
ended_at: ended ? new Date() : null,
})
.where(eq(workflowRunsTable.id, run_id))
.returning();
@@ -67,10 +78,7 @@ export async function POST(request: Request) {
// Need to filter out only comfy deploy serverless
// Also multiply with the gpu selection
if (workflow_run.machine_type == "comfy-deploy-serverless") {
if (
(status === "success" || status === "failed") &&
workflow_run.user_id
) {
if (ended && workflow_run.user_id) {
const sub = await getCurrentPlan({
user_id: workflow_run.user_id,
org_id: workflow_run.org_id,
+4 -2
View File
@@ -16,7 +16,7 @@ export function LiveStatus({
(state) =>
state.data
.filter((x) => x.id === run.id)
.sort((a, b) => b.timestamp - a.timestamp)?.[0]
.sort((a, b) => b.timestamp - a.timestamp)?.[0],
);
let status = run.status;
@@ -51,7 +51,9 @@ export function LiveStatus({
<>
<TableCell>
{data && status != "success"
? `${data.json.event} - ${data.json.data.node}`
? `${data.json.event}${
data.json.data.node ? " - " + data.json.data.node : ""
}`
: "-"}
</TableCell>
<TableCell className="truncate text-right">
+4
View File
@@ -19,6 +19,7 @@ import { getDuration, getRelativeTime } from "@/lib/getRelativeTime";
import { type findAllRuns } from "@/server/findAllRuns";
import { Suspense } from "react";
import { LiveStatus } from "./LiveStatus";
import { LogsType, LogsViewer } from "@/components/LogsViewer";
export async function RunDisplay({
run,
@@ -75,6 +76,9 @@ export async function RunDisplay({
<RunInputs run={run} />
<Suspense>
<RunOutputs run_id={run.id} />
{run.run_log && (
<LogsViewer logs={JSON.parse(run.run_log) as LogsType} />
)}
</Suspense>
</div>
{/* <div className="max-h-96 overflow-y-scroll">{view}</div> */}
+2
View File
@@ -17,6 +17,8 @@ export function StatusBadge({
);
case "success":
return <Badge variant="success">{status}</Badge>;
case "timeout":
return <Badge variant="amber">{status}</Badge>;
case "failed":
return <Badge variant="destructive">{status}</Badge>;
}
+4 -7
View File
@@ -104,6 +104,7 @@ export const workflowRunStatus = pgEnum("workflow_run_status", [
"failed",
"started",
"queued",
"timeout",
]);
export const deploymentEnvironment = pgEnum("deployment_environment", [
@@ -172,6 +173,7 @@ export const workflowRunsTable = dbSchema.table("workflow_runs", {
machine_type: machinesType("machine_type"),
user_id: text("user_id"),
org_id: text("org_id"),
run_log: text("run_log"),
});
export const workflowRunRelations = relations(
@@ -385,13 +387,8 @@ export const modelUploadType = pgEnum("model_upload_type", [
"other",
]);
// https://www.answeroverflow.com/m/1125106227387584552
export const modelTypes = [
"checkpoint",
"lora",
"embedding",
"vae",
] as const
// https://www.answeroverflow.com/m/1125106227387584552
export const modelTypes = ["checkpoint", "lora", "embedding", "vae"] as const;
export const modelType = pgEnum("model_type", modelTypes);
export type modelEnumType = (typeof modelTypes)[number];