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
+36
View File
@@ -0,0 +1,36 @@
const httpStatus = {
// Informational
CONTINUE: 100,
SWITCHING_PROTOCOLS: 101,
PROCESSING: 102,
// Success
OK: 200,
CREATED: 201,
ACCEPTED: 202,
NO_CONTENT: 204,
// Redirection
MOVED_PERMANENTLY: 301,
FOUND: 302,
SEE_OTHER: 303,
NOT_MODIFIED: 304,
TEMPORARY_REDIRECT: 307,
// Client Error
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
METHOD_NOT_ALLOWED: 405,
CONFLICT: 409,
GONE: 410,
UNSUPPORTED_MEDIA_TYPE: 415,
// Server Error
INTERNAL_SERVER_ERROR: 500,
NOT_IMPLEMENTED: 501,
SERVICE_UNAVAILABLE: 503
};
module.exports = { httpStatus };
+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}