npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@drizzle-http/opossum-circuit-breaker

v3.1.0

Published

Opossum implementation for Drizzle-HTTP

Downloads

5

Readme

Opossum Circuit Breaker Adapter · ci npm (scoped) GitHub license

Circuit breaker adapter with Opossum.

Installation

Make sure we have the core module @Drizzle-Http/core installed.

npm i @drizzle-http/core
npm i @drizzle-http/opossum-circuit-breaker

Usage

Usage typically looks like the example below:

import { CircuitBreakerCallAdapterFactory } from "@drizzle-http/opossum-circuit-breaker";
import { DrizzleBuilder } from "@drizzle-http/core";
import { UndiciCallFactory } from "@drizzle-http/undici";
import { CircuitBreaker } from "@drizzle-http/opossum-circuit-breaker";
import { Fallback } from "@drizzle-http/opossum-circuit-breaker";
import { GET } from "@drizzle-http/core";

class CustomerApi {
  @GET('/customers')
  @CircuitBreaker({ /* Opossum CircuitBreaker.Options */ })
  @Fallback('customersAlt')
  customers(): Promise<Customer[]> { }
}

class CustomerApiFallbacks {
  customersAlt(id: string, error: Error): Promise<Customer> {
    // Fallback implementation
  }
}

const factory = new CircuitBreakerCallAdapterFactory({ options: { /* global options */ }, fallbacks: new CustomerApiFallbacks() })
const api = DrizzleBuilder
  .newBuilder()
  .baseUrl(/* base url */)
  .callFactory(new UndiciCallFactory())
  .addCallAdapterFactories(factory)
  .build()
  .create(CustomerApi)

Features

All functionalities from Opossum are available.
Some features and extensions:

Fallback

Fallback methods follow Opossum specification, same argument list and an error argument at the end.
There are 3 ways to specify a fallback for a circuit breaker:

  • Specify a fallback class in CircuitBreakerCallAdapterFactory constructor. If a method name matches the one specified in the API class, it will be used as a fallback automatically.
  • Apply the decorator @Fallback() and:
    • If @Fallback() decorator argument is a string, it will try to find the method on the fallback class specified in the CircuitBreakerCallAdapterFactory constructor.
    • If @Fallback decorator receives a function, this function will be the fallback.

Make sure the fallback methods have right signature: same argument list + error at the end and same return type.

Registry

All circuit breakers associated with a CircuitBreakerCallAdapterFactory are stored in a registry instance. CircuitBreakerCallAdapterFactory accepts a parameter registry. You can pass a custom Registry implementation.

The circuit breaker instance is only stored in the registry after the first execution. If you want to change the circuit breaker behaviour, prefer to use a LifeCycleListener implementation.