🔄 refactor(config): Move connectWithTimeout Outside of Helpers Module (#1513)

This commit is contained in:
Danny Avila 2024-01-07 14:43:27 -05:00 committed by GitHub
parent 9144680ffb
commit 050a92b318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 40 deletions

32
config/connect.js Normal file
View file

@ -0,0 +1,32 @@
const path = require('path');
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
const connectDb = require('~/lib/db/connectDb');
async function connect() {
/**
* Connect to the database
* - If it takes a while, we'll warn the user
*/
let timeout = setTimeout(() => {
console.orange(
'This is taking a while... You may need to check your connection if this fails.',
);
timeout = setTimeout(() => {
console.orange('Still going... Might as well assume the connection failed...');
timeout = setTimeout(() => {
console.orange('Error incoming in 3... 2... 1...');
}, 13000);
}, 10000);
}, 5000);
// Attempt to connect to the database
try {
console.orange('Warming up the engines...');
await connectDb();
clearTimeout(timeout);
} catch (e) {
console.error(e);
process.exit(1);
}
}
module.exports = connect;