-
Notifications
You must be signed in to change notification settings - Fork 589
Expand file tree
/
Copy pathwarm-up-worker.ts
More file actions
45 lines (37 loc) · 1.68 KB
/
Copy pathwarm-up-worker.ts
File metadata and controls
45 lines (37 loc) · 1.68 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/* Warm-up worker entry point. */
import { parentPort } from 'worker_threads';
import { Analyzer } from './analyzer';
import type { EditLocIndex } from './edit-loc-diff';
import type { Session, Workspace } from './types';
interface WarmUpWorkerRequest {
sessions: Session[];
editLocIndex?: EditLocIndex;
workspaces?: Map<string, Workspace>;
}
const port = parentPort;
if (!port) throw new Error('warm-up-worker: must run as worker thread');
function isWarmUpWorkerRequest(value: unknown): value is WarmUpWorkerRequest {
if (typeof value !== 'object' || value === null) return false;
const request = value as Record<string, unknown>;
return Array.isArray(request.sessions) &&
(request.editLocIndex === undefined || request.editLocIndex instanceof Map) &&
(request.workspaces === undefined || request.workspaces instanceof Map);
}
port.on('message', (msg) => {
try {
if (!isWarmUpWorkerRequest(msg)) throw new Error('Invalid warm-up worker payload');
const analyzer = new Analyzer(msg.sessions, msg.editLocIndex, msg.workspaces);
const antiPatterns = analyzer.getAntiPatterns();
const configHealth = analyzer.getConfigHealth();
port.postMessage({ type: 'result', antiPatterns, configHealth });
} catch (e) {
port.postMessage({
type: 'error',
message: e instanceof Error ? e.message : String(e),
});
}
});