overall v1

This commit is contained in:
andrei-mihnea-cerbu
2024-11-12 14:00:30 +02:00
parent a5e4fc030d
commit 5ea32b2a3a
34 changed files with 1131 additions and 781 deletions
+6 -37
View File
@@ -13,16 +13,15 @@ export class WorkerManager {
this.workers = []; // Initialize the array to store workers
}
async startNetworkScannerWorker(udpPort: number, okPage: string, errorPage: string, applicationInfoPath: string): Promise<void> {
async startNetworkScannerWorker(udpPort: number, tcpPort: number, okPage: string, errorPage: string, databaseResetPage: string, userConfigPath: string, applicationInfoPath: string): Promise<void> {
return new Promise((resolve, reject) => {
const worker = new Worker(path.join(this.pathToWorkerDir, 'network_scanner_worker.js'), {
workerData: { udpPort, okPage, errorPage, applicationInfoPath }, // Pass necessary data to the worker
workerData: { udpPort, tcpPort, okPage, errorPage, databaseResetPage, userConfigPath, applicationInfoPath }, // Pass necessary data to the worker
});
this.workers.push(worker); // Store the worker reference
worker.on('message', (data) => {
console.log(data);
if (data.type === 'changeContent') {
this.windowManager.changeContent(data.page);
}
@@ -43,7 +42,7 @@ export class WorkerManager {
});
}
// Start the Connection Pool Worker
// Start the Directories Watcher Worker
async startDirectoriesWatchersWorker(memoryManagerPath: string, applicationInfoPath: string): Promise<void> {
return new Promise((resolve, reject) => {
const worker = new Worker(path.join(this.pathToWorkerDir, 'directories_watcher_worker.js'), {
@@ -53,18 +52,18 @@ export class WorkerManager {
this.workers.push(worker); // Store the worker reference
worker.on('message', (data) => {
console.log('Connection Pool Worker message:', data);
console.log('DirectoriesWatcher message:', data);
});
worker.on('error', (err) => {
console.error('Connection Pool Worker error:', err);
console.error('DirectoriesWatcher error:', err);
worker.terminate();
this.removeWorker(worker);
reject(err); // Reject the promise if there's an error
});
worker.on('exit', (code) => {
console.log(`Connection Pool Worker exited with code ${code}`);
console.log(`DirectoriesWatcher exited with code ${code}`);
this.removeWorker(worker); // Remove worker reference when it exits
resolve(); // Resolve when the worker exits cleanly
});
@@ -169,36 +168,6 @@ export class WorkerManager {
});
}
// Method to start the Announcement Worker
async startAnnouncementWorker(applicationInfoPath: string, clientPort: number, message: string): Promise<void> {
return new Promise((resolve, reject) => {
const worker = new Worker(path.join(this.pathToWorkerDir, 'send_announcement_worker.js'), {
workerData: { applicationInfoPath, clientPort, message }, // Pass necessary data to the worker
});
this.workers.push(worker); // Store the worker reference
worker.on('message', async (data) => {
await new Promise((resolve) => setTimeout(resolve, 3000)); // Wait for 1 second
this.windowManager.changeContent('main_menu');
this.windowManager.showAlert(`${data.message}`)
});
worker.on('error', (err) => {
console.error('Announcement Worker error:', err);
worker.terminate();
this.removeWorker(worker);
reject(err); // Reject the promise if there's an error
});
worker.on('exit', (code) => {
console.log(`Announcement Worker exited with code ${code}`);
this.removeWorker(worker); // Remove worker reference when it exits
resolve(); // Resolve when the worker exits cleanly
});
});
}
// Close all running workers
closeAllWorkers(): void {
console.log('Terminating all running workers...');