How to use brakes - 3 common examples

To help you get started, we’ve selected a few brakes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anatomic / zero-to-live-fp-js-workshop / src / services / getFixtures / getFixtures.js View on Github external
const app = micro(async (req, res) => {
  const end = responseTimer.startTimer();
  const reqUrl = url.parse(req.url);
  if (reqUrl.pathname === '/metrics') {
    return client.register.metrics();
  }

  if (reqUrl.pathname === '/hystrix.stream') {
    res.setHeader('Content-Type', 'text/event-stream;charset=UTF-8');
    res.setHeader(
      'Cache-Control',
      'no-cache; no-store; max-age=0; must-revalidate'
    );
    res.setHeader('Pragma', 'no-cache');
    return Brakes.getGlobalStats().getHystrixStream();
  }

  requestCount.inc();
  requestGauge.inc();

  worldCupFixtures
    .runWith({
      apiBase: API_BASE,
      apiToken: API_TOKEN,
      timeout: TIMEOUT,
    })
    .fork(
      e => {
        requestGauge.dec(); // Need to have this in both branches otherwise leaks be happenin'
        end();
        send(res, e.status || 500, {
github nest-cloud / nestcloud / packages / feign / hystrix.controller.ts View on Github external
onModuleInit(): any {
        const Brakes = require('brakes');
        this.globalStats = Brakes.getGlobalStats();
    }
github ERS-HCL / nxplorerjs-microservice-starter / server / common / config / hystrix.ts View on Github external
export const configHystrix = () => {
  if (process.env.STREAM_HYSTRIX === 'true') {
    const globalStats = Brakes.getGlobalStats();
    http
      .createServer((req, res) => {
        res.setHeader('Content-Type', 'text/event-stream;charset=UTF-8');
        res.setHeader(
          'Cache-Control',
          'no-cache, no-store, max-age=0, must-revalidate'
        );
        res.setHeader('Pragma', 'no-cache');
        globalStats.getHystrixStream().pipe(res);
      })
      .listen(3001, () => {
        console.log('---------------------');
        console.log('Hystrix Stream now live at localhost:3001/hystrix.stream');
        console.log('---------------------');
      });
  }

brakes

Node.js Circuit Breaker Pattern

MIT
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis

Popular brakes functions