@wiredcraft/health-checks

    2.2.2 • Public • Published

    @wiredcraft/health-checks

    A generic health checker.

    Usage

    const { HealthChecker, HealthStatus } = require('@wiredcraft/health-checks');
    const healthChecker = new HealthChecker();
    healthChecker.addCheck(async () => {
        if (Math.random() > 0.5) {
            throw new Error('RandomFailure');
        }
    }, 'db', HealthStatus.Unhealthy.name, ['default', 'all']);
    healthChecker.addCheck(async () => {
        if (Math.random() > 0.5) {
            throw new Error('RandomFailure');
        }
    }, 'external-service', HealthStatus.Degraded.name, ['all']);
    
    // By default, it will filter checks which includes 'default' tag
    const res = await healthChecker.getStatus();
    // res will be something like 
    // {
    //     "status": "unhealthy",
    //     "checks": [
    //         {
    //             "name": "db",
    //             "state": "unhealthy",
    //             "data": {
    //                 "reason": "RandomFailure"
    //             }
    //         }
    //     ]
    // }
    
    // You can use other tag to filter the checks
    const res = await healthChecker.getStatus('all');
    // res will be something like 
    // {
    //     "status": "degraded",
    //     "checks": [
    //         {
    //             "name": "db",
    //             "state": "healthy",
    //             "data": {
    //                 "reason": ""
    //             }
    //         },
    //         {
    //             "name": "external-service",
    //             "state": "degraded",
    //             "data": {
    //                 "reason": "RandomFailure"
    //             }
    //         }
    //     ]
    // }

    For more details, see scenarios in test cases.

    Install

    npm i @wiredcraft/health-checks

    DownloadsWeekly Downloads

    232

    Version

    2.2.2

    License

    MIT

    Unpacked Size

    5.85 kB

    Total Files

    7

    Last publish

    Collaborators

    • raohael_biland
    • yadong_zhang
    • kikiatwcl
    • liyachun01
    • echoyueyu
    • wiredcraft-bot
    • makara
    • xavierchow
    • wwayne
    • drakexiang
    • kaleocheng
    • flyingant
    • ccharlieli
    • illuminati1911
    • ilya_wiredcraft
    • rankun203
    • superbogy
    • miffyliye
    • lalawow
    • bsdelf
    • maxiaobao
    • shuaibird
    • juhas
    • cyrilselasi
    • xiao_t
    • agreatfool
    • haishanh
    • chopperlee2011
    • woodpig07
    • dowla
    • ivanbar
    • eronekogin
    • kuno
    • xpol
    • wangjianting
    • estemomento