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