chore(web): ensure builder connect to the specific instance id
This commit is contained in:
@@ -29,6 +29,7 @@ export default async function Page({
|
||||
<CardContent>
|
||||
{machine.status == "building" && (
|
||||
<MachineBuildLog
|
||||
instance_id={machine.build_machine_instance_id!}
|
||||
machine_id={params.machine_id}
|
||||
endpoint={process.env.MODAL_BUILDER_URL!}
|
||||
/>
|
||||
|
||||
@@ -9,20 +9,24 @@ import useWebSocket from "react-use-websocket";
|
||||
export function MachineBuildLog({
|
||||
machine_id,
|
||||
endpoint,
|
||||
instance_id,
|
||||
}: {
|
||||
machine_id: string;
|
||||
endpoint: string;
|
||||
instance_id: string;
|
||||
}) {
|
||||
const [logs, setLogs] = useState<LogsType>([]);
|
||||
const [finished, setFinished] = useState(false);
|
||||
|
||||
const wsEndpoint = endpoint.replace(/^http/, "ws");
|
||||
const query = { fly_instance_id: instance_id };
|
||||
const { lastMessage, readyState } = useWebSocket(
|
||||
`${wsEndpoint}/ws/${machine_id}`,
|
||||
{
|
||||
shouldReconnect: () => !finished,
|
||||
reconnectAttempts: 20,
|
||||
reconnectInterval: 1000,
|
||||
queryParams: query,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ export const machinesTable = dbSchema.table("machines", {
|
||||
status: machinesStatus("status").notNull().default("ready"),
|
||||
snapshot: jsonb("snapshot").$type<any>(),
|
||||
models: jsonb("models").$type<any>(),
|
||||
build_machine_instance_id: text("build_machine_instance_id"),
|
||||
build_log: text("build_log"),
|
||||
});
|
||||
|
||||
|
||||
@@ -189,6 +189,16 @@ async function buildMachine(
|
||||
})
|
||||
.where(eq(machinesTable.id, b.id));
|
||||
throw new Error(`Error: ${result.statusText} ${error_log}`);
|
||||
} else {
|
||||
// setting the build machine id
|
||||
const json = await result.json();
|
||||
await db
|
||||
.update(machinesTable)
|
||||
.set({
|
||||
...data,
|
||||
build_machine_instance_id: json.build_machine_instance_id,
|
||||
})
|
||||
.where(eq(machinesTable.id, b.id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user