fix: show status after create workflow run
This commit is contained in:
		
							parent
							
								
									4ea9cb61dd
								
							
						
					
					
						commit
						942660d505
					
				
							
								
								
									
										60
									
								
								web/src/app/api/create-run/route.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								web/src/app/api/create-run/route.ts
									
									
									
									
									
										Normal 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,
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -84,7 +84,7 @@ export async function POST(request: Request) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return NextResponse.json(
 | 
					    return NextResponse.json(
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        run_id: run_id,
 | 
					        run_id: run_id.workflow_run_id,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        status: 200,
 | 
					        status: 200,
 | 
				
			||||||
 | 
				
			|||||||
@ -118,7 +118,9 @@ export function RunWorkflowButton({
 | 
				
			|||||||
        setIsLoading(true);
 | 
					        setIsLoading(true);
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          const origin = window.location.origin;
 | 
					          const origin = window.location.origin;
 | 
				
			||||||
          await createRun(origin, workflow_version_id, machine);
 | 
					          await callServerPromise(
 | 
				
			||||||
 | 
					            createRun(origin, workflow_version_id, machine)
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
          // console.log(res.json());
 | 
					          // console.log(res.json());
 | 
				
			||||||
          setIsLoading(false);
 | 
					          setIsLoading(false);
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
 | 
				
			|||||||
@ -102,7 +102,10 @@ export async function createRun(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  revalidatePath(`/${workflow_version_data.workflow_id}`);
 | 
					  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(
 | 
					  // return NextResponse.json(
 | 
				
			||||||
  //   {
 | 
					  //   {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user