More progress

This commit is contained in:
cte 2025-03-31 02:21:52 -07:00
parent 4ea5f21792
commit 689e104455
2 changed files with 35 additions and 17 deletions

View file

@ -28,7 +28,6 @@ import {
createTaskMetrics,
updateTaskMetrics,
} from "@benchmark/db"
import { inChunksOf } from "@benchmark/lib"
import { IpcServer, IpcClient } from "@benchmark/ipc"
import { __dirname, extensionDevelopmentPath, exercisesPath } from "./paths.js"
@ -108,25 +107,39 @@ const run = async (toolbox: GluegunToolbox) => {
// })
// })
const chunks = inChunksOf(tasks, 3)
const maxConcurrency = 3
const runningPromises: Promise<void>[] = []
for (const chunk of chunks) {
await Promise.all(
chunk.map(async (task) => {
if (task.finishedAt === null) {
await runExercise({ run, task, server })
}
const processTask = async (task: Task) => {
if (task.finishedAt === null) {
await runExercise({ run, task, server })
}
if (task.passed === null) {
const passed = await runUnitTest({ task })
await updateTask(task.id, { passed })
}
}),
)
break
if (task.passed === null) {
const passed = await runUnitTest({ task })
await updateTask(task.id, { passed })
}
}
for (const task of tasks) {
const taskPromise = processTask(task)
runningPromises.push(taskPromise)
taskPromise.finally(() => {
const index = runningPromises.indexOf(taskPromise)
if (index > -1) {
runningPromises.splice(index, 1)
}
})
if (runningPromises.length >= maxConcurrency) {
await Promise.race(runningPromises)
}
}
await Promise.all(runningPromises)
const result = await finishRun(run.id)
console.log("[cli#run]", result)

View file

@ -8,6 +8,7 @@ import type { Run, TaskMetrics } from "@benchmark/db"
import { formatCurrency, formatDuration } from "@/lib"
import { Button, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui"
import { useMemo } from "react"
import Link from "next/link"
export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null })[] }) {
const router = useRouter()
@ -33,7 +34,11 @@ export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null
{visibleRuns.length ? (
visibleRuns.map(({ taskMetrics, ...run }) => (
<TableRow key={run.id}>
<TableCell>{run.id}</TableCell>
<TableCell>
<Button variant="link" asChild>
<Link href={`/runs/${run.id}`}>{run.id}</Link>
</Button>
</TableCell>
<TableCell>{run.model}</TableCell>
<TableCell>{new Date(run.createdAt).toLocaleString()}</TableCell>
<TableCell>{run.passed}</TableCell>