forked from vercel/next-evals-oss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.ts
More file actions
46 lines (39 loc) · 1.01 KB
/
worker.ts
File metadata and controls
46 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bun
import { parentPort, workerData } from 'worker_threads';
import { runEval } from './lib/eval-runner';
interface WorkerData {
evalPath: string;
dryRun: boolean;
verbose: boolean;
debug: boolean;
}
async function runWorker() {
if (!parentPort || !workerData) {
throw new Error('Worker must be run with parentPort and workerData');
}
const { evalPath, dryRun, verbose, debug }: WorkerData = workerData;
try {
const result = await runEval(evalPath, dryRun, verbose, debug);
parentPort.postMessage({
success: true,
evalPath,
result
});
} catch (error) {
parentPort.postMessage({
success: false,
evalPath,
error: error instanceof Error ? error.message : String(error)
});
}
}
// Run the worker
runWorker().catch((error) => {
if (parentPort) {
parentPort.postMessage({
success: false,
evalPath: workerData?.evalPath || 'unknown',
error: error instanceof Error ? error.message : String(error)
});
}
});