fix: show status after create workflow run

This commit is contained in:
BennyKok 2023-12-15 19:48:51 +08:00
parent 4ea9cb61dd
commit 942660d505
4 changed files with 68 additions and 3 deletions

View File

@ -0,0 +1,60 @@
import { parseDataSafe } from "../../../lib/parseDataSafe";
import { createRun } from "../../../server/createRun";
import { getRunsOutput } from "@/server/getRunsOutput";
import { NextResponse } from "next/server";
import { z } from "zod";
const Request = z.object({
workflow_version_id: z.string(),
machine_id: z.string(),
});
const Request2 = z.object({
run_id: z.string(),
});
export async function GET(request: Request) {
const [data, error] = await parseDataSafe(Request2, request);
if (!data || error) return error;
const run = await getRunsOutput(data.run_id);
return NextResponse.json(run, {
status: 200,
});
}
export async function POST(request: Request) {
const [data, error] = await parseDataSafe(Request, request);
if (!data || error) return error;
const origin = new URL(request.url).origin;
const { workflow_version_id, machine_id } = data;
try {
const workflow_run_id = await createRun(
origin,
workflow_version_id,
machine_id
);
return NextResponse.json(
{
workflow_run_id: workflow_run_id.workflow_run_id,
},
{
status: 200,
}
);
} catch (error: any) {
return NextResponse.json(
{
error: error.message,
},
{
status: 500,
}
);
}
}

View File

@ -84,7 +84,7 @@ export async function POST(request: Request) {
return NextResponse.json(
{
run_id: run_id,
run_id: run_id.workflow_run_id,
},
{
status: 200,

View File

@ -118,7 +118,9 @@ export function RunWorkflowButton({
setIsLoading(true);
try {
const origin = window.location.origin;
await createRun(origin, workflow_version_id, machine);
await callServerPromise(
createRun(origin, workflow_version_id, machine)
);
// console.log(res.json());
setIsLoading(false);
} catch (error) {

View File

@ -102,7 +102,10 @@ export async function createRun(
revalidatePath(`/${workflow_version_data.workflow_id}`);
return workflow_run[0].id;
return {
workflow_run_id: workflow_run[0].id,
message: "Successfully workflow run",
};
// return NextResponse.json(
// {