Skip to content

Commit

Permalink
feat: smoke test trigger on edit, ui updates for validation status pa…
Browse files Browse the repository at this point in the history
…ge (#135)

* feat: trigger smoke test on edit, fix maxDuration

* update maxduration

* update ui

* fix ui state management, redirect to edit on fail
  • Loading branch information
vcashwin authored Jan 31, 2025
1 parent 7461cf4 commit 081d504
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 105 deletions.
44 changes: 37 additions & 7 deletions apps/app/app/api/pipelines/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ import { uploadFile } from "@/app/api/pipelines/storage";
import { pipelineSchema } from "@/lib/types";
import { createServerClient } from "@repo/supabase/server";
import { z } from "zod";
import { triggerSmokeTest } from "./validation";
import { createSmokeTestStream } from "./validation";

export async function publishPipeline(pipelineId: string, userId: string) {
const supabase = await createServerClient();

await validateUser(userId);

const { data: updatedPipeline, error: updateError } = await supabase
.from("pipelines")
.upsert({
id: pipelineId,
is_private: false,
})
.select()
.single();

if (updateError) throw new Error(updateError.message);

return { pipeline: updatedPipeline };
}

export async function updatePipeline(body: any, userId: string) {
const supabase = await createServerClient();
Expand All @@ -15,16 +36,22 @@ export async function updatePipeline(body: any, userId: string) {
if (!validationResult.success) {
throw new z.ZodError(validationResult.error.errors);
}

const { data, error } = await supabase
const pipelineId = body.id;
const { data: pipeline, error } = await supabase
.from("pipelines")
.update(validationResult.data)
.eq("id", body.id)
.eq("id", pipelineId)
.eq("author", userId)
.select();
.select()
.single();

if (error) throw new Error(error.message);
return data;

// Create a smoke test stream using the pipeline for pre-publication validation with new config saved
const smokeTestStream = await createSmokeTestStream(pipelineId);
await triggerSmokeTest(smokeTestStream.stream_key);

return { pipeline, smokeTestStream };
}

export async function editPipelineFromFormData(
Expand Down Expand Up @@ -56,6 +83,9 @@ export async function editPipelineFromFormData(
config: comfyUiJson,
};

const pipeline = await updatePipeline(pipelineData, userId);
return pipeline;
const { pipeline, smokeTestStream } = await updatePipeline(
pipelineData,
userId
);
return { pipeline, smokeTestStream };
}
1 change: 1 addition & 0 deletions apps/app/app/api/streams/[id]/sse/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getStoredStreamStatus } from "@/app/api/pipelines/validation";

// Prevents this route's response from being cached on Vercel
export const dynamic = "force-dynamic";
export const maxDuration = 300;

export async function GET(
request: Request,
Expand Down
7 changes: 6 additions & 1 deletion apps/app/app/pipelines/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export default async function Page({
}

if (isValidationMode) {
return <ValidatePipeline streamId={searchParams.streamId} />;
return (
<ValidatePipeline
pipelineId={pipelineId}
streamId={searchParams.streamId}
/>
);
}

const pipeline = await getPipeline(pipelineId);
Expand Down
6 changes: 4 additions & 2 deletions apps/app/components/pipeline/edit-pipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { Loader2, LoaderCircleIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { toast } from "sonner";
import FileUploadDropzone, { FileType } from "./json-upload";
import PipelineStatus from "./status";
import { useRouter } from "next/navigation";

export default function EditPipeline({
pipeline,
}: {
pipeline: PipelineSchema & { id: string };
}) {
const router = useRouter();
const { authenticated, user, ready: isAuthLoaded } = usePrivy();
const [formData, setFormData] = useState<Record<string, unknown>>(() => {
return {
Expand Down Expand Up @@ -56,9 +57,10 @@ export default function EditPipeline({
formDataToSend.append(decamelize(key), value as any);
});
console.log("Form data to send::", formDataToSend, formData);
const pipeline = await editPipelineFromFormData(formDataToSend, user.id);
const { pipeline, smokeTestStream } = await editPipelineFromFormData(formDataToSend, user.id);
toast.dismiss(toastId);
toast.success("Pipeline saved successfully");
router.push(`/pipelines/${pipeline.id}?streamId=${smokeTestStream.id}&validation=true`);
} catch (error) {
toast.dismiss(toastId);
const errorMessage =
Expand Down
81 changes: 0 additions & 81 deletions apps/app/components/pipeline/status.tsx

This file was deleted.

Loading

0 comments on commit 081d504

Please sign in to comment.