From 689e104455b15fa4824d5bb5c40326a456151ab3 Mon Sep 17 00:00:00 2001 From: cte Date: Mon, 31 Mar 2025 02:21:52 -0700 Subject: [PATCH] More progress --- benchmark/apps/cli/src/index.ts | 45 +++++++++++++++++++---------- benchmark/apps/web/src/app/home.tsx | 7 ++++- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/benchmark/apps/cli/src/index.ts b/benchmark/apps/cli/src/index.ts index 19a00b718f..c4cf395902 100644 --- a/benchmark/apps/cli/src/index.ts +++ b/benchmark/apps/cli/src/index.ts @@ -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[] = [] - 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) diff --git a/benchmark/apps/web/src/app/home.tsx b/benchmark/apps/web/src/app/home.tsx index 7aa8cccde0..46204529d3 100644 --- a/benchmark/apps/web/src/app/home.tsx +++ b/benchmark/apps/web/src/app/home.tsx @@ -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 }) => ( - {run.id} + + + {run.model} {new Date(run.createdAt).toLocaleString()} {run.passed}