feat: add rebuild machine option

This commit is contained in:
BennyKok 2024-01-12 18:56:02 +08:00
parent 2ff19f53d0
commit b8e478c8ee
2 changed files with 51 additions and 10 deletions

View File

@ -32,6 +32,7 @@ import {
import {
addCustomMachine,
addMachine,
buildMachine,
deleteMachine,
disableMachine,
enableMachine,
@ -202,14 +203,28 @@ export const columns: ColumnDef<Machine>[] = [
</DropdownMenuItem>
)}
{machine.type === "comfy-deploy-serverless" && (
<>
<DropdownMenuItem asChild>
<a
target="_blank"
href={machine.endpoint.replace("comfyui-api", "comfyui-app")}
href={machine.endpoint.replace(
"comfyui-api",
"comfyui-app"
)}
>
Open ComfyUI
</a>
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
buildMachine({
id: machine.id,
});
}}
>
Rebuild
</DropdownMenuItem>
</>
)}
<DropdownMenuItem onClick={() => setOpen(true)}>
Edit

View File

@ -113,7 +113,7 @@ export const updateCustomMachine = withServerPromise(
.where(eq(machinesTable.id, id));
// Perform custom build if there are changes
await buildMachine(data, currentMachine);
await _buildMachine(data, currentMachine);
redirect(`/machines/${id}`);
} else {
revalidatePath("/machines");
@ -123,6 +123,32 @@ export const updateCustomMachine = withServerPromise(
}
);
export const buildMachine = withServerPromise(
async ({ id }: { id: string }) => {
const { userId } = auth();
if (!userId) return { error: "No user id" };
const currentMachine = await db.query.machinesTable.findFirst({
where: eq(machinesTable.id, id),
});
if (!currentMachine) return { error: "Machine not found" };
const datas = await db
.update(machinesTable)
.set({
status: "building",
endpoint: "not-ready",
})
.where(eq(machinesTable.id, id))
.returning();
// Perform custom build if there are changes
await _buildMachine(datas[0], currentMachine);
redirect(`/machines/${id}`);
}
);
export const addCustomMachine = withServerPromise(
async (data: z.infer<typeof addCustomMachineSchema>) => {
const { userId, orgId } = auth();
@ -143,14 +169,14 @@ export const addCustomMachine = withServerPromise(
const b = a[0];
await buildMachine(data, b);
await _buildMachine(data, b);
redirect(`/machines/${b.id}`);
// revalidatePath("/machines");
return { message: "Machine Building" };
}
);
async function buildMachine(
async function _buildMachine(
data: z.infer<typeof addCustomMachineSchema>,
b: MachineType
) {