1.1.0 • Published 5 years ago
@greenrenge/gracefully v1.1.0
@greenrenge/gracefully
A lightship module for support kubernetes liveness and readiness
Description
This module is a simple wrapper of the original lightship library which helps to easily initialize the ready callback functions for multiple source of ready interconnected services being used by the application (eg. database) or configuration loading of the application.
Features
- add
createReadinesswhich help to split lightshipsignalReadyto multiple functions - server exposes on paths
/health/liveand/readyas the original lightship does but listen on port13000by default - add
enableLogoption to print lightship logs - add
randomPortOnLocalto reserve random port behavior when the process is run on local as the original lightship does, default tofalse
Install
npm install --save @greenrenge/gracefullyUsage
Readiness
import createLightship from "@greenrenge/gracefully"
const { createReadiness } = createLightship()
const [mongooseDbReady, expressReady, senecaReady] = createReadiness(3)
// for mongoose connection
mongoose.connect(/* connectionString */)
mongoose.connection.on("connected", () => mongooseDbReady())
// for express
const app = express()
app.listen(3000, () => expressReady())
// for seneca
require("seneca")({ some_options: 123 })
.use("community-plugin-1", { some_config: SOME_CONFIG })
.use("community-plugin-2")
.listen(/* ... */)
.client(/* ... */)
.ready(() => senecaReady())in case of making service back to not ready state, we get functions by 2 ways ..
const [mongooseDbReady] = createReadiness()
// first way, return from ready function call
const mongooseNotReady = mongooseDbReady()
mongooseNotReady()
// second way, by property `toNotReady` of ready function
mongooseDbReady.toNotReady()License
MIT © Greenrenge