> Would love feedback on the API design
I'd suggest to drop the DSL, at the end of the day, a good old class with a constructor stored in a constant is much more more transparent:
class PaymentService
STRIPE_CIRCUIT = BreakerMachines::Circuit.new(
threshold: { failures: 3, within: 1.minute },
reset_after: 30.seconds,
fallback: ->{ { error: "Payment queued for later" } }
)
def charge(amount)
STRIPE_CIRCUIT.wrap do
Stripe::Charge.create(amount: amount)
end
end
end
Just my 2 cents though.