BACKEND DONE FOR ALL APPS

This commit is contained in:
andrei-mihnea-cerbu
2024-10-21 18:34:45 +03:00
parent 4157ca9e7d
commit ab1eaec413
349 changed files with 17199 additions and 14015 deletions
@@ -0,0 +1,38 @@
import { workerData, parentPort } from 'worker_threads';
import { BackupRetrievalWorker} from '../helpers/backup_retrieval'; // Assuming the class is in the same folder
// Destructure the data passed from the WorkerManager
const {
userConfigPath,
applicationInfoPath,
clientPort,
destinationPath
}: {
userConfigPath: string,
applicationInfoPath: string,
clientPort: number,
destinationPath: string
} = workerData;
// Initialize the BackupRetrievalWorker
const backupRetrievalWorker = new BackupRetrievalWorker(
userConfigPath,
applicationInfoPath,
clientPort,
destinationPath
);
// Start the backup retrieval process
backupRetrievalWorker.start()
.then(() => {
parentPort?.postMessage({
success: true,
message: 'Backup retrieval completed successfully.'
});
})
.catch((error: any) => {
parentPort?.postMessage({
success: false,
message: `Backup retrieval failed: ${error.message}`
});
});
@@ -0,0 +1,52 @@
import { workerData } from 'worker_threads';
import { UsersInfoFetcher } from '../helpers/users_info_fetcher';
import {BackupManager} from "../helpers/backup_manager";
import {FileSharer} from "../helpers/file_sharer";
import {DepartmentSharer} from "../helpers/department_sharer";
// Destructure the required information from workerData
const { usersConfigPath, applicationInfoPath, memoryManagerPath, queueManagerPath, tcpPort } = workerData;
const usersInfoFetcher = new UsersInfoFetcher(applicationInfoPath, memoryManagerPath, tcpPort);
usersInfoFetcher.start()
.then(() => {
console.log('Users Info Fetcher started successfully');
})
.catch((error: any) => {
console.error('Error starting Users Info Fetcher:', error);
});
const backupManager = new BackupManager(
usersConfigPath,
applicationInfoPath,
memoryManagerPath,
tcpPort
);
backupManager.start()
.then(() => {
console.log('Backup Manager started successfully');
})
.catch((error: any) => {
console.error('Error starting Backup Manager:', error);
});
const fileSharer = new FileSharer(queueManagerPath, tcpPort);
fileSharer.start()
.then(() => {
console.log('File Sharer started successfully');
})
.catch((error: any) => {
console.error('Error starting File Sharer:', error);
});
const departmentSharer = new DepartmentSharer(usersConfigPath, applicationInfoPath, memoryManagerPath, tcpPort);
departmentSharer.start()
.then(() => {
console.log('Department Sharer started successfully');
})
.catch((error: any) => {
console.error('Error starting Department Sharer:', error);
});
+14
View File
@@ -0,0 +1,14 @@
import {UdpServer} from "../network/udp/udp_server";
import {TcpServer} from "../network/tcp/tcp_server";
import {workerData} from "worker_threads";
let udpServer: UdpServer | null = null;
let tcpServer: TcpServer | null = null;
const {USER_UDP_PORT, USER_TCP_PORT, HOST} = workerData;
udpServer = new UdpServer(HOST, USER_UDP_PORT);
udpServer.start();
tcpServer = new TcpServer(HOST, USER_TCP_PORT);
tcpServer.start();
+43
View File
@@ -0,0 +1,43 @@
import {DirectoryWatcher} from "../helpers/directory_watcher";
import {workerData} from "worker_threads";
const {
memoryManagerPath,
applicationInfoPath,
} = workerData;
const backupDirectoryManager = new DirectoryWatcher(memoryManagerPath, applicationInfoPath, 'backupDirectory');
const departmentShareManager = new DirectoryWatcher(memoryManagerPath, applicationInfoPath, 'departmentDirectory');
const shareFileManager = new DirectoryWatcher(memoryManagerPath, applicationInfoPath, 'shareDirectory');
// Backup directory manager check loop
const backupIntervalId = setInterval(async () => {
if (await backupDirectoryManager.initialize()) {
clearInterval(backupIntervalId); // Stop the loop once initialized
console.log('BackupDirectoryManager successfully initialized.');
} else {
console.log('Retrying BackupDirectoryManager initialization...');
}
}, 60000); // Check every 60 seconds
// Department share manager check loop
const departmentIntervalId = setInterval(async () => {
if (await departmentShareManager.initialize()) {
clearInterval(departmentIntervalId); // Stop the loop once initialized
console.log('DepartmentShareManager successfully initialized.');
} else {
console.log('Retrying DepartmentShareManager initialization...');
}
}, 60000); // Check every 60 seconds
// Department share manager check loop
const shareIntervalId = setInterval(async () => {
if (await shareFileManager.initialize()) {
clearInterval(shareIntervalId); // Stop the loop once initialized
console.log('DepartmentShareManager successfully initialized.');
} else {
console.log('Retrying DepartmentShareManager initialization...');
}
}, 60000); // Check every 60 seconds