Created
July 28, 2022 16:19
-
-
Save kissmygritts/8781324509fa480db87cea06042bc19b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function testConnection (db) { | |
try { | |
const c = await db.connect() | |
c.done() | |
console.log('CONNECTED') | |
} catch (error) { | |
console.log('RETRYING CONNECTION') | |
await testConnection(db) | |
} | |
} | |
const wait = delay => { | |
return new Promise(resolve => { | |
setTimeout(() => { resolve() }, delay) | |
}) | |
} | |
function waitForDb (db) { | |
return new Promise(async (resolve, reject) => { | |
let count = 0 | |
let dbReady = false | |
while (dbReady && count <= 6) { | |
count++ | |
try { | |
const c = await db.connect() | |
c.done() | |
dbReady = true | |
console.log('CONNECTED TO DATABASE') | |
} catch (error) { | |
console.log('DATABASE ISNT READY, RETRYING') | |
} | |
await wait(count * count * 1000) | |
} | |
if (count > 6) reject() | |
resolve() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment