-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug where initial check was false
- Loading branch information
1 parent
cea5f85
commit 6f75b29
Showing
2 changed files
with
32 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
import client from "./db.config"; | ||
|
||
async function getDB() { | ||
await client.connect(); | ||
async function getDB(): Promise<void> { | ||
await client.connect(); | ||
await client.end() | ||
} | ||
|
||
function runWithTimeout(fn: () => void, timeout: number, interval: number = 100) { | ||
return new Promise<void>((resolve, reject) => { | ||
const startTime = Date.now(); | ||
|
||
const handle = setInterval(() => { | ||
const elapsedTime = Date.now() - startTime; | ||
|
||
if (elapsedTime >= timeout) { | ||
clearInterval(handle); | ||
resolve(); | ||
} else { | ||
try { | ||
fn(); | ||
} catch (error) { | ||
clearInterval(handle); | ||
reject(error); | ||
} | ||
} | ||
}, interval); | ||
}); | ||
} | ||
function runWithTimeout(fn: () => Promise<void>, timeout: number, interval: number) : Promise<void> { | ||
return new Promise<void>((resolve, reject) => { | ||
const startTime = Date.now(); | ||
|
||
const handle = setInterval(async () => { | ||
const elapsedTime = Date.now() - startTime; | ||
|
||
const args: string[] = process.argv; | ||
const timeout: number = parseInt(args[2]); | ||
if (elapsedTime >= timeout) { | ||
clearInterval(handle); | ||
resolve(); | ||
} else { | ||
try { | ||
await fn(); | ||
clearInterval(handle); | ||
resolve(); | ||
} catch (error) { | ||
clearInterval(handle); | ||
reject(error); | ||
} | ||
} | ||
}, interval); | ||
}); | ||
} | ||
|
||
await runWithTimeout(getDB, timeout); | ||
runWithTimeout(getDB, parseInt(process.argv[2]), parseInt(process.argv[2])) | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
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