@fresh8/f8-copacetic
A package to help your service check the health of its dependencies.
Last updated 3 years ago by tobycoleman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @fresh8/f8-copacetic 
SYNC missed versions from official npm registry.

Copacetic

JavaScript Style Guide Coverage Status CircleCI

A package to help your service check the health of its dependencies.

Requirements

Node v6.4.0 and above

Installation

npm install @fresh8/f8-copacetic --save

Quick Start

const Copacetic = require('f8-copacetic')
const level = require('f8-copacetic').dependencyLevel

const copacetic = Copacetic()

// register a dependency
copacetic.registerDependency({
  name: 'My-Dependency',
  url: 'https://my-Dependency.io',
  // defaults to SOFT
  dependency: level.HARD
})


// check its health
copacetic
  .check({
    name: 'My-Dependency',
    retries: 2
  })
  .on('healthy', (Dependency) => {
    /**
     * { name: 'My-Dependency',
     *   healthy: true/false,
     *   lastChecked: Date,
     *   level: 'SOFT'
     * }
     */
  })
  .on('unhealthy', (Dependency) => {
    // handle degraded state...
    copacetic.deregisterDependency('My-Dependency')
  })

Copacetic ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new Copacetic([name])

Param Type Default Description
[name] String '' the name of your service

copacetic.isHealthy ⇒ Boolean

Kind: instance property of Copacetic
Returns: Boolean - Copacetic is healthy when all hard dependencies are healthy

copacetic.healthInfo ⇒ Array.<DependencyHealth>

Kind: instance property of Copacetic
Returns: Array.<DependencyHealth> - health information on all dependencies

copacetic.getDependency(dependency) ⇒ Dependency

Kind: instance method of Copacetic

Param Type
dependency Dependency | String

copacetic.isDependencyRegistered(dependency) ⇒ Boolean

Kind: instance method of Copacetic
Returns: Boolean - whether the dependency has been registered

Param Type
dependency Dependency | String

copacetic.registerDependency(opts) ⇒ Copacetic

adds a dependency to a Copacetic instance

Kind: instance method of Copacetic

Param Type Description
opts Object the configuration for a dependency

copacetic.deregisterDependency(name) ⇒ Copacetic

removes a dependency from a Copacetic instance

Kind: instance method of Copacetic

Param Type Description
name String the name used to identify a dependency

copacetic.pollAll([interval], [parallel], [schedule]) ⇒ Copacetic

polls the health of all registered dependencies

Kind: instance method of Copacetic

Param Type Default
[interval] String '5 seconds'
[parallel] Boolean true
[schedule] String 'start'

copacetic.poll([dependencies], [interval], [parallel], [schedule]) ⇒ Copacetic

polls the health of a set of dependencies

Kind: instance method of Copacetic
Emits: health

Param Type Default Description
[dependencies] Array.<Object> an explicit set of dependencies to be polled
[interval] String '5 seconds'
[parallel] Boolean true kick of health checks in parallel or series
[schedule] String 'start' schedule the next check to start (interval - ms)

Example

copacetic.poll({
  dependencies: [
    { name: 'my-dep' },
    { name: 'my-other-dep', retries: 2 }
  ],
  schedule: 'end',
  interval: '1 minute 30 seconds'
})
.on('health', (serviceHealth) => {
  // do something with the result
  // [{ name: String, health: Boolean, level: HARD/SOFT, lastCheck: Date }]
})

copacetic.stop()

stops polling registered dependencies

Kind: instance method of Copacetic

copacetic.checkAll([parallel]) ⇒ Copacetic

checks the health of all registered dependencies

Kind: instance method of Copacetic

Param Type Default Description
[parallel] Boolean true kick of health checks in parallel or series

copacetic.check([name], [dependencies], [retries], [parallel]) ⇒ Copacetic

checks the health of a set, or single dependency

Kind: instance method of Copacetic
Emits: health, healthy, unhealthy

Param Type Default Description
[name] String the identifier of a single dependency to be checked
[dependencies] Array.<Object> an explicit set of dependencies to be checked
[retries] Integer 1 how many times should a dependency be checked, until it is deemed unhealthy
[parallel] Boolean true kick of health checks in parallel or series

Example

copacetic.check({ name: 'my-dependency' })

Example

copacetic.check({ name: 'my-dependency', retries: 5 })
.on('healthy', serviceHealth => { // do stuff })
.on('unhealthy', serviceHealth => { // handle degraded state })

Example

copacetic.check({ dependencies: [
  { name: 'my-dep' },
  { name: 'my-other-dep', retries: 2 }
] })
.on('health', (servicesHealth) => {
  // do something with the result
  // [{ name: String, health: Boolean, level: HARD/SOFT, lastCheck: Date }]
})

"healthy"

Health information about a single dependency

Kind: event emitted by Copacetic

"unhealthy"

Health information about a single dependency

Kind: event emitted by Copacetic

"health"

Health information on a set of dependencies

Kind: event emitted by Copacetic

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 4
Dependencies (6)
Dev Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |