external_service icon indicating copy to clipboard operation
external_service copied to clipboard

Expose fuse state

Open davidsulc opened this issue 5 years ago • 1 comments

I'm new to using circuit breakers, etc. so perhaps there's a better way to achieve what I'm looking for: feel free to correct me.

I want to process batches of data fetched from a remote service, process these, and then store the processed results in the DB. My plan is to use ExternalService to wrap calls to both the external API and the DB (with separate fuses, of course).

Here's the rub: fetching the data from the remote API is time consuming so it would be pretty wasteful to kick off the job if the DB's fuse is blown. Instead, I want to return an immediate response indicating the service is unavailable/downgraded if either fuses for the remote API or the DB is blown. This approach seems to be in line with the philosophy of the circuit breaker pattern: avoid resource waste (and cascading failures) by returning and immediate result when a fuse is blown.

Therefore, wouldn't it make sense to introduce something like ExternalService.available?(:foo) and ExternalService.all_available?([:foo, :bar]) (or fuse_blown? and fuses_blown?)? I'd be willing to take a stab at those if that's the case.

davidsulc avatar Mar 13 '19 07:03 davidsulc

Hi @davidsulc, sorry for the delayed response. I don’t seem to get email notifications from GitHub for some reason so I just now saw this.

I'll consider adding some sort of fuse status function(s) to ExternalService, but in the meantime you can accomplish what you want by using the :fuse API directly:

def available?(fuse), do: :fuse.ask(fuse, :sync) == :ok

def all_available?(fuses), do: Enum.all?(fuses, &available/1)

jvoegele avatar Mar 18 '19 11:03 jvoegele