Have ideas to improve npm?Join in the discussion! »

    @greenrenge/gracefully

    1.1.0 • Public • Published

    @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 createReadiness which help to split lightship signalReady to multiple functions
    • server exposes on paths /health /live and /ready as the original lightship does but listen on port 13000 by default
    • add enableLog option to print lightship logs
    • add randomPortOnLocal to reserve random port behavior when the process is run on local as the original lightship does, default to false

    Install

    npm install --save @greenrenge/gracefully

    Usage

    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

    Install

    npm i @greenrenge/gracefully

    DownloadsWeekly Downloads

    59

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    31.2 kB

    Total Files

    14

    Last publish

    Collaborators

    • avatar