mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-09 01:01:29 +03:00
Updated style of settings for DB
MongoDB connection string test now only tests once
This commit is contained in:
@@ -1609,7 +1609,7 @@ app.post('/api/transferDB', optionalJwt, async (req, res) => {
|
||||
app.post('/api/testConnectionString', optionalJwt, async (req, res) => {
|
||||
let success = null;
|
||||
let error = '';
|
||||
success = await db_api.connectToDB(5, true);
|
||||
success = await db_api.connectToDB(0, true);
|
||||
if (!success) error = 'Connection string failed.';
|
||||
|
||||
res.send({success: success, error: error});
|
||||
|
||||
@@ -76,22 +76,25 @@ exports.connectToDB = async (retries = 5, no_fallback = false) => {
|
||||
const success = await exports._connectToDB();
|
||||
if (success) return true;
|
||||
|
||||
logger.warn(`MongoDB connection failed! Retrying ${retries} times...`);
|
||||
const retry_delay_ms = 2000;
|
||||
for (let i = 0; i < retries; i++) {
|
||||
const retry_succeeded = await exports._connectToDB();
|
||||
if (retry_succeeded) {
|
||||
logger.info(`Successfully connected to DB after ${i+1} attempt(s)`);
|
||||
return true;
|
||||
}
|
||||
if (retries) {
|
||||
logger.warn(`MongoDB connection failed! Retrying ${retries} times...`);
|
||||
const retry_delay_ms = 2000;
|
||||
for (let i = 0; i < retries; i++) {
|
||||
const retry_succeeded = await exports._connectToDB();
|
||||
if (retry_succeeded) {
|
||||
logger.info(`Successfully connected to DB after ${i+1} attempt(s)`);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i !== retries - 1) {
|
||||
logger.warn(`Retry ${i+1} failed, waiting ${retry_delay_ms}ms before trying again.`);
|
||||
await utils.wait(retry_delay_ms);
|
||||
} else {
|
||||
logger.warn(`Retry ${i+1} failed.`);
|
||||
if (i !== retries - 1) {
|
||||
logger.warn(`Retry ${i+1} failed, waiting ${retry_delay_ms}ms before trying again.`);
|
||||
await utils.wait(retry_delay_ms);
|
||||
} else {
|
||||
logger.warn(`Retry ${i+1} failed.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (no_fallback) {
|
||||
logger.error('Failed to connect to MongoDB. Verify your connection string is valid.');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user