Skip to content

Commit 689e104

Browse files
committed
More progress
1 parent 4ea5f21 commit 689e104

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

benchmark/apps/cli/src/index.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
createTaskMetrics,
2929
updateTaskMetrics,
3030
} from "@benchmark/db"
31-
import { inChunksOf } from "@benchmark/lib"
3231
import { IpcServer, IpcClient } from "@benchmark/ipc"
3332

3433
import { __dirname, extensionDevelopmentPath, exercisesPath } from "./paths.js"
@@ -108,25 +107,39 @@ const run = async (toolbox: GluegunToolbox) => {
108107
// })
109108
// })
110109

111-
const chunks = inChunksOf(tasks, 3)
110+
const maxConcurrency = 3
111+
const runningPromises: Promise<void>[] = []
112112

113-
for (const chunk of chunks) {
114-
await Promise.all(
115-
chunk.map(async (task) => {
116-
if (task.finishedAt === null) {
117-
await runExercise({ run, task, server })
118-
}
113+
const processTask = async (task: Task) => {
114+
if (task.finishedAt === null) {
115+
await runExercise({ run, task, server })
116+
}
119117

120-
if (task.passed === null) {
121-
const passed = await runUnitTest({ task })
122-
await updateTask(task.id, { passed })
123-
}
124-
}),
125-
)
118+
if (task.passed === null) {
119+
const passed = await runUnitTest({ task })
120+
await updateTask(task.id, { passed })
121+
}
122+
}
123+
124+
for (const task of tasks) {
125+
const taskPromise = processTask(task)
126+
runningPromises.push(taskPromise)
126127

127-
break
128+
taskPromise.finally(() => {
129+
const index = runningPromises.indexOf(taskPromise)
130+
131+
if (index > -1) {
132+
runningPromises.splice(index, 1)
133+
}
134+
})
135+
136+
if (runningPromises.length >= maxConcurrency) {
137+
await Promise.race(runningPromises)
138+
}
128139
}
129140

141+
await Promise.all(runningPromises)
142+
130143
const result = await finishRun(run.id)
131144
console.log("[cli#run]", result)
132145

benchmark/apps/web/src/app/home.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Run, TaskMetrics } from "@benchmark/db"
88
import { formatCurrency, formatDuration } from "@/lib"
99
import { Button, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui"
1010
import { useMemo } from "react"
11+
import Link from "next/link"
1112

1213
export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null })[] }) {
1314
const router = useRouter()
@@ -33,7 +34,11 @@ export function Home({ runs }: { runs: (Run & { taskMetrics: TaskMetrics | null
3334
{visibleRuns.length ? (
3435
visibleRuns.map(({ taskMetrics, ...run }) => (
3536
<TableRow key={run.id}>
36-
<TableCell>{run.id}</TableCell>
37+
<TableCell>
38+
<Button variant="link" asChild>
39+
<Link href={`/runs/${run.id}`}>{run.id}</Link>
40+
</Button>
41+
</TableCell>
3742
<TableCell>{run.model}</TableCell>
3843
<TableCell>{new Date(run.createdAt).toLocaleString()}</TableCell>
3944
<TableCell>{run.passed}</TableCell>

0 commit comments

Comments
 (0)