36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { parentPort, workerData } from 'node:worker_threads';
|
|
import { ImportError } from '../../src/shared/errors';
|
|
import {
|
|
executeGpoWorkerOperation,
|
|
type GpoBackupWorkerExecutionRequest,
|
|
type GpoInventoryExecutionRequest,
|
|
type GpoRecognitionExecutionRequest,
|
|
type MicrosoftBaselineWorkerExecutionRequest
|
|
} from './gpo-inventory-executor';
|
|
|
|
const port = parentPort;
|
|
if (!port) throw new Error('GPO-Inventar-Worker benötigt einen übergeordneten Thread.');
|
|
|
|
const request = workerData as
|
|
| GpoInventoryExecutionRequest
|
|
| GpoRecognitionExecutionRequest
|
|
| GpoBackupWorkerExecutionRequest
|
|
| MicrosoftBaselineWorkerExecutionRequest;
|
|
void executeGpoWorkerOperation(request)
|
|
.then(result => port.postMessage(result.operation === 'backup'
|
|
? { ok: true, backup: result.value }
|
|
: result.operation === 'microsoft-baseline'
|
|
? { ok: true, microsoftBaseline: result.value }
|
|
: result.operation === 'recognition'
|
|
? { ok: true, recognition: result.value }
|
|
: { ok: true, inventory: result.value }))
|
|
.catch((error: unknown) => {
|
|
const importError = error instanceof ImportError ? error : null;
|
|
port.postMessage({
|
|
ok: false,
|
|
error: {
|
|
message: error instanceof Error ? error.message : 'Unbekannter GPO-Verarbeitungsfehler',
|
|
diagnostics: importError?.diagnostics ?? []
|
|
}
|
|
});
|
|
}); |