CEO updated

This commit is contained in:
andrei-mihnea-cerbu
2024-04-20 03:18:44 +03:00
parent 869305a491
commit 57c2c7ec55
81 changed files with 3517 additions and 1035 deletions
+33
View File
@@ -0,0 +1,33 @@
const lockfile = require('proper-lockfile');
async function lockFile(filePath) {
try {
await lockfile.lock(filePath, {
realpath: false,
retries: {
retries: 10, // Number of retries
factor: 2, // The exponential factor
minTimeout: 1000, // The number of milliseconds before starting the first retry
maxTimeout: 5000, // The maximum number of milliseconds between two retries
randomize: true, // Randomizes the timeouts by multiplying with a factor between 1 to 2
}
});
console.log(`File locked: ${filePath}`);
} catch (error) {
console.error(`Error locking file ${filePath}: ${error.message}`);
throw error; // Propagate the error if unable to lock after retries
}
}
async function unlockFile(filePath) {
try {
await lockfile.unlock(filePath);
console.log(`File unlocked: ${filePath}`);
} catch (error) {
console.error(`Error unlocking file ${filePath}: ${error.message}`);
// Decide whether to throw the error or not, based on your error handling strategy
throw error;
}
}
module.exports = {lockFile, unlockFile}