Closed peterkeen closed 9 years ago
I think I would prefer to see something like an optional event_wrapper
(for lack of a better name right now) or maybe just an around
configuration that takes a Proc (that in turn calls the normal backend.instrument
routine). This would allow people to effectively run both before and after hooks instead of just an after hook.
Example usage (psuedo, untested so far):
StripeEvent.around = lambda do |event, subscribers|
# stuff before (e.g. log a start time)
subscribers.call
# stuff after (e.g. log total processing time or track fully processed event
# to help prevent replay attacks)
end
Example instrument
implementation and default around
config implementation (also untested):
module StripeEvent
class << self
# ...
def instrument(params)
# ...
if event
subscribers = lambda { backend.instrument(namespace.call(event[:type]), event) }
around.call(event, subscribers)
end
end
# ...
end
#...
self.around = lambda { |event, subscribers| subscribers.call }
# ...
Just brainstorming for now. There's probably room to clean this up, but I can turn this into a more formal pull-request if that would help.
This adds an
event_finalizer
hook that will be called after all subscribers have been notified of an event. This lets us record a completely successful event, while allowing Stripe to retry any failures.Fixes #53