Files
FACULTATE-LICENTA/User/src/workers/backup_retrieval_worker.ts
T

44 lines
1.2 KiB
TypeScript

import { BackupRetrievalWorker } from '../helpers/backup_retrieval'
import dotenv from 'dotenv'
// Load environment variables from .env file if it exists
dotenv.config()
// Retrieve configuration from environment variables
const clientPort = Number(process.env.CLIENT_PORT)
const destinationPath = process.env.DESTINATION_PATH as string
const pathToDatabaseFile = process.env.DATABASE_FILE_PATH as string
// Validate that all required environment variables are present
if (!pathToDatabaseFile || !clientPort || !destinationPath) {
console.error('Error: Missing required environment variables.')
process.exit(1)
}
// Initialize the BackupRetrievalWorker
const backupRetrievalWorker = new BackupRetrievalWorker(
pathToDatabaseFile,
clientPort,
destinationPath,
)
// Start the backup retrieval process
backupRetrievalWorker.start().then(() => {
console.log('Backup retrieval process completed successfully.')
})
process.on('SIGTERM', async () => {
console.log('Received SIGTERM. Cleaning up...')
await cleanupAndExit()
})
process.on('SIGINT', async () => {
console.log('Received SIGINT. Cleaning up...')
await cleanupAndExit()
})
async function cleanupAndExit() {
console.log('Cleanup complete. Exiting.')
process.exit(0)
}