mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
using cp for plans
This commit is contained in:
47
backend/src/services/SchedulingService.ts
Normal file
47
backend/src/services/SchedulingService.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// src/services/schedulingService.ts
|
||||
import { Worker } from 'worker_threads';
|
||||
import path from 'path';
|
||||
import { Employee, ShiftPlan } from '../models/Employee.js';
|
||||
|
||||
export interface ScheduleRequest {
|
||||
shiftPlan: ShiftPlan;
|
||||
employees: Employee[];
|
||||
availabilities: Availability[];
|
||||
constraints: Constraint[];
|
||||
}
|
||||
|
||||
export interface ScheduleResult {
|
||||
assignments: Assignment[];
|
||||
violations: Violation[];
|
||||
success: boolean;
|
||||
resolutionReport: string[];
|
||||
processingTime: number;
|
||||
}
|
||||
|
||||
export class SchedulingService {
|
||||
async generateOptimalSchedule(request: ScheduleRequest): Promise<ScheduleResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const worker = new Worker(path.resolve(__dirname, '../workers/scheduler-worker.js'), {
|
||||
workerData: request
|
||||
});
|
||||
|
||||
// Timeout nach 110 Sekunden
|
||||
const timeout = setTimeout(() => {
|
||||
worker.terminate();
|
||||
reject(new Error('Scheduling timeout after 110 seconds'));
|
||||
}, 110000);
|
||||
|
||||
worker.on('message', (result: ScheduleResult) => {
|
||||
clearTimeout(timeout);
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
worker.on('error', reject);
|
||||
worker.on('exit', (code) => {
|
||||
if (code !== 0) {
|
||||
reject(new Error(`Worker stopped with exit code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user