3 ms·
> 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 mo
by byroot 1y ago
> 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.
- seuros 1y agoMerci pour la remarque ! Your 2 space credits are worth their weight in dilithium. Funny thing is the gem originally started exactly like that, pure explicit constructors. Then I wrapped it with the DSL sugar but the explicit approach never lost its capability. Both paths lead to the same destination. I actually loved this suggestion so much that I added a whole section called "Captain Byroot's Guide to Explicit Circuit Construction" to the docs: https://github.com/seuros/breaker_machines/blob/master/docs/ADVANCED_PATTERNS.md#the-explicit-way-captain-byroots-preferred-method https://github.com/seuros/breaker_machines/blob/master/docs/.... The resistance appreciates your feedback.