mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
log shutdown reasons
This commit is contained in:
parent
76cf268ef4
commit
6e1d12d3b8
@ -51,10 +51,9 @@ export class AuthenticationResolver {
|
||||
if (!openConnectionJwtPayload.url) {
|
||||
throw new Error(`invalid url of community with publicKey ${argsPublicKey.asHex()}`)
|
||||
}
|
||||
methodLogger.debug(`vor DbFedCommunity.findOneByOrFail()...`, { publicKey: argsPublicKey.asHex() })
|
||||
methodLogger.debug(`before DbFedCommunity.findOneByOrFail()...`, { publicKey: argsPublicKey.asHex() })
|
||||
const fedComA = await DbFedCommunity.findOneByOrFail({ publicKey: argsPublicKey.asBuffer() })
|
||||
methodLogger.debug(`nach DbFedCommunity.findOneByOrFail()...`, fedComA)
|
||||
methodLogger.debug('fedComA', new FederatedCommunityLoggingView(fedComA))
|
||||
methodLogger.debug(`after DbFedCommunity.findOneByOrFail()...`, new FederatedCommunityLoggingView(fedComA))
|
||||
if (!openConnectionJwtPayload.url.startsWith(fedComA.endPoint)) {
|
||||
throw new Error(`invalid url of community with publicKey ${argsPublicKey.asHex()}`)
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import { getLogger } from 'log4js'
|
||||
// config
|
||||
import { CONFIG } from './config'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from './config/const'
|
||||
import { onShutdown, ShutdownReason } from 'shared'
|
||||
|
||||
async function main() {
|
||||
// init logger
|
||||
@ -27,6 +28,13 @@ async function main() {
|
||||
`GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}/api/${CONFIG.FEDERATION_API}`,
|
||||
)
|
||||
}
|
||||
onShutdown(async (reason, details) => {
|
||||
if (ShutdownReason.SIGINT === reason || ShutdownReason.SIGTERM === reason) {
|
||||
logger.info(`graceful shutdown: ${reason}`)
|
||||
} else {
|
||||
logger.error(`crash: ${reason} ${details}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,13 @@ export class BinaryData {
|
||||
}
|
||||
logging.debug(`constructor() input type: ${typeof input}`)
|
||||
logging.debug(`constructor() input isBuffer: ${Buffer.isBuffer(input)}`)
|
||||
logging.debug(`constructor() input: ${input}`)
|
||||
if (typeof input === 'string') {
|
||||
logging.debug(`constructor() input: ${input}`)
|
||||
} else if (Buffer.isBuffer(input)) {
|
||||
logging.debug(`constructor() input: ${input.toString('hex')}`)
|
||||
} else {
|
||||
logging.debug(`constructor() unexpected input type: ${typeof input}`)
|
||||
}
|
||||
if (typeof input === 'string') {
|
||||
this.buf = Buffer.from(input, 'hex')
|
||||
this.hex = input
|
||||
@ -38,6 +44,8 @@ export class BinaryData {
|
||||
}
|
||||
|
||||
isSame(other: BinaryData): boolean {
|
||||
logging.debug(`isSame() this: ${this.buf}`)
|
||||
logging.debug(`isSame() other: ${other.buf}`)
|
||||
return this.buf.compare(other.buf) === 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export * from './updateField'
|
||||
export * from './BinaryData'
|
||||
export * from './BinaryData'
|
||||
export * from './onShutdown'
|
||||
43
shared/src/helper/onShutdown.ts
Normal file
43
shared/src/helper/onShutdown.ts
Normal file
@ -0,0 +1,43 @@
|
||||
export enum ShutdownReason {
|
||||
SIGINT = 'SIGINT',
|
||||
SIGTERM = 'SIGTERM',
|
||||
UNCAUGHT_EXCEPTION = 'UNCAUGHT_EXCEPTION',
|
||||
UNCAUGHT_REJECTION = 'UNCAUGHT_REJECTION',
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup graceful shutdown for the process
|
||||
* @param gracefulShutdown will be called if process is terminated
|
||||
*/
|
||||
export function onShutdown(shutdownHandler: (reason: ShutdownReason, details?: string) => Promise<void>) {
|
||||
const signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM']
|
||||
signals.forEach(sig => {
|
||||
process.on(sig, async () => {
|
||||
await shutdownHandler(sig as ShutdownReason)
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
|
||||
process.on('uncaughtException', async (err, origin) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_EXCEPTION, `${origin}: ${err}`)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', async (reason, promise) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_REJECTION, `${promise}: ${reason}`)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
if (process.platform === "win32") {
|
||||
const rl = require("readline").createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
})
|
||||
rl.on("SIGINT", () => {
|
||||
process.emit("SIGINT" as any)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user