Start race condition
This commit is contained in:
parent
08a2e77871
commit
d160430ac8
|
@ -22,6 +22,7 @@ import * as redis from "./utilities/redis"
|
|||
import { events, logging, middleware } from "@budibase/backend-core"
|
||||
import { initialise as initialiseWebsockets } from "./websocket"
|
||||
import { startup } from "./startup"
|
||||
import { retry } from "./utilities/retry"
|
||||
const Sentry = require("@sentry/node")
|
||||
const destroyable = require("server-destroy")
|
||||
|
||||
|
@ -80,7 +81,11 @@ server.on("close", async () => {
|
|||
})
|
||||
|
||||
export default server.listen(env.PORT || 0, async () => {
|
||||
await startup(app, server)
|
||||
if (!env.isTest()) {
|
||||
await startup(app, server)
|
||||
} else {
|
||||
await retry(async () => await startup(app, server))
|
||||
}
|
||||
})
|
||||
|
||||
const shutdown = () => {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
export async function retry<T extends (...arg0: any[]) => any>(
|
||||
fn: T,
|
||||
maxTry: number = 5,
|
||||
retryCount = 1
|
||||
): Promise<Awaited<ReturnType<T>>> {
|
||||
const currRetry = typeof retryCount === "number" ? retryCount : 1
|
||||
try {
|
||||
const result = await fn()
|
||||
return result
|
||||
} catch (e) {
|
||||
console.log(`Retry ${currRetry} failed.`)
|
||||
if (currRetry > maxTry) {
|
||||
console.log(`All ${maxTry} retry attempts exhausted`)
|
||||
throw e
|
||||
}
|
||||
return retry(fn, maxTry, currRetry + 1)
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ enum Mode {
|
|||
SELF = "self",
|
||||
}
|
||||
|
||||
export async function retry<T extends (...arg0: any[]) => any>(
|
||||
async function retry<T extends (...arg0: any[]) => any>(
|
||||
fn: T,
|
||||
maxTry: number = 5,
|
||||
retryCount = 1
|
||||
|
|
Loading…
Reference in New Issue