New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

serviced

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serviced

Microservice dependency readiness probe

  • 2.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Serviced

Build Status Coverage Status Dependency Status npm version

Microservice dependency readiness probe

Small utility to probe for backing-service availability using http calls and promises. This will likely evolve to be more compatible but, for now, it uses features available in Node 6+. Feel free to send pull requests or open issues to make it compatible with earlier versions.

Motivation

When working with microservices, we often find we need to be prepared for variable times in backing service availability. Most times these are available and ready before we even probe them but some times they are not like in the case of a service needing to apply some configuration specific to a consuming service, etc. Serviced provides a way to probe multiple services with varying probe and retry configurations wrapped in a promise so you can, for example, not start an API server until all its backing services are available and ready.

Usage

npm i serviced

Test that a single service returns status code 200.

const Serviced = require('serviced');

new Serviced('http://exmample.com').then(() => {
  // Your service is online and returns status code 200.
});

Test that multiple services return status code 200.

new Serviced('http://svc-a.com', 'http://svc-b.com').then(() => {
  // Both services are online and return status codes 200.
});

Test the response body from a service request with a test function.

new Serviced({
  url: 'http://svc-a.com',
  test(body) {
    return body.foo === true;
  },
}).then(() => {
  // Service is online and response passes supplied test.
});

Test the response body from multiple service requests with test functions.

new Serviced({
  url: 'http://svc-a.com',
  test(body) {
    return body.foo === true;
  },
}, {
  url: 'http://svc-b.com',
  test(body) {
    return body.bar === true;
  },
}).then(() => {
  // Services are online and responses pass supplied tests.
});

Different options for multiple services.

// http://svc-a.com is only tested for a 200 response.
// http://svc-b.com's response body is passed to your own test function.
new Serviced('http://svc-a.com', {
  url: 'http://svc-b.com',
  test(body) {
    return body.bar === true;
  },
}).then(() => {
  // Services are online and responses pass supplied tests.
});

Pass additional options to underlying request and retry modules.

The optional .request and .retry objects are passed through to the request and retry module instances respectively so you can control those as you deem necessary. It's a straight passthrough so please read their docs to find out what options are available for each.

new Serviced({
  url: 'http://svc-a.com',
  request: { // pass options to request
    auth: {
      user: 'username',
      pass: 'password',
    }
  },
  retry: { // pass options to retry
    retries: 2,
    maxTimeout: 2000,
  },
  test(body) {
    return body.foo === true;
  },
}).then(() => {
  // Service is online and response passes supplied test.
});

Contributing

  • Fork the repo.
  • npm i
  • npm start to work on the library. This runs the tests continuously watching for changes but without test output (debug output instead).
  • Make your changes
  • npm t to run the tests with no debug output (tap output instead).
  • npm run cov to run coverage report.
  • npm run linter to run eslint.
  • Submit a PR.

Change log

  • 2.0.0 Breaking changes from 1.x. I switched to retry over backoff primarily because of how it handles errors but also for simplicity.

Keywords

FAQs

Package last updated on 26 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc