Review comments and test fix.
This commit is contained in:
parent
b7075de0cd
commit
e439d7097b
|
@ -0,0 +1 @@
|
|||
module.exports = require("./src/logging")
|
|
@ -0,0 +1,16 @@
|
|||
const NonErrors = ["AccountError"]
|
||||
|
||||
function isSuppressed(e) {
|
||||
return e && e["suppressAlert"]
|
||||
}
|
||||
|
||||
module.exports.logAlert = (message, e = null) => {
|
||||
if (e && NonErrors.includes(e.name) && isSuppressed(e)) {
|
||||
return
|
||||
}
|
||||
let errorJson = ""
|
||||
if (e) {
|
||||
errorJson = ": " + JSON.stringify(e, Object.getOwnPropertyNames(e))
|
||||
}
|
||||
console.error(`bb-alert: ${message} ${errorJson}`)
|
||||
}
|
|
@ -14,7 +14,7 @@ const automations = require("./automations/index")
|
|||
const Sentry = require("@sentry/node")
|
||||
const fileSystem = require("./utilities/fileSystem")
|
||||
const bullboard = require("./automations/bullboard")
|
||||
const context = require("@budibase/backend-core/context")
|
||||
const { logAlert } = require("@budibase/backend-core/logging")
|
||||
const { Thread } = require("./threads")
|
||||
import redis from "./utilities/redis"
|
||||
import * as migrations from "./migrations"
|
||||
|
@ -70,7 +70,8 @@ if (env.isProd()) {
|
|||
const server = http.createServer(app.callback())
|
||||
destroyable(server)
|
||||
|
||||
let shuttingDown = false
|
||||
let shuttingDown = false,
|
||||
errCode = 0
|
||||
server.on("close", async () => {
|
||||
// already in process
|
||||
if (shuttingDown) {
|
||||
|
@ -84,7 +85,9 @@ server.on("close", async () => {
|
|||
await redis.shutdown()
|
||||
await Thread.shutdown()
|
||||
api.shutdown()
|
||||
process.exit()
|
||||
if (!env.isTest()) {
|
||||
process.exit(errCode)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = server.listen(env.PORT || 0, async () => {
|
||||
|
@ -107,7 +110,8 @@ process.on("uncaughtException", err => {
|
|||
if (err && err["code"] === "ERR_INVALID_CHAR") {
|
||||
return
|
||||
}
|
||||
console.error(err)
|
||||
errCode = -1
|
||||
logAlert("Uncaught exception.", err)
|
||||
shutdown()
|
||||
})
|
||||
|
||||
|
@ -119,7 +123,7 @@ process.on("SIGTERM", () => {
|
|||
// not recommended in a clustered environment
|
||||
if (!env.HTTP_MIGRATIONS) {
|
||||
migrations.migrate().catch(err => {
|
||||
console.error("Error performing migrations. Exiting.\n", err)
|
||||
logAlert("Error performing migrations. Exiting.", err)
|
||||
shutdown()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ const destroyable = require("server-destroy")
|
|||
const koaBody = require("koa-body")
|
||||
const koaSession = require("koa-session")
|
||||
const { passport } = require("@budibase/backend-core/auth")
|
||||
const { logAlert } = require("@budibase/backend-core/logging")
|
||||
const logger = require("koa-pino-logger")
|
||||
const http = require("http")
|
||||
const api = require("./api")
|
||||
|
@ -61,7 +62,8 @@ if (env.isProd()) {
|
|||
const server = http.createServer(app.callback())
|
||||
destroyable(server)
|
||||
|
||||
let shuttingDown = false
|
||||
let shuttingDown = false,
|
||||
errCode = 0
|
||||
server.on("close", async () => {
|
||||
if (shuttingDown) {
|
||||
return
|
||||
|
@ -71,7 +73,9 @@ server.on("close", async () => {
|
|||
console.log("Server Closed")
|
||||
}
|
||||
await redis.shutdown()
|
||||
process.exit()
|
||||
if (!env.isTest()) {
|
||||
process.exit(errCode)
|
||||
}
|
||||
})
|
||||
|
||||
const shutdown = () => {
|
||||
|
@ -85,7 +89,8 @@ module.exports = server.listen(parseInt(env.PORT || 4002), async () => {
|
|||
})
|
||||
|
||||
process.on("uncaughtException", err => {
|
||||
console.error(err)
|
||||
errCode = -1
|
||||
logAlert("Uncaught exception.", err)
|
||||
shutdown()
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue