class Sequent::Core::EventPublisher
EventPublisher
ensures that, for every thread, events will be published
in the order in which they are queued for publishing.
This potentially introduces a wrinkle into your plans:
You therefore should not split a "unit of work" across multiple threads.
If you want other behaviour, you are free to implement your own version of EventPublisher
and configure Sequent to use it.
Public Instance Methods
Source
# File lib/sequent/core/event_publisher.rb, line 30 def publish_events(events) return if configuration.disable_event_handlers events.each { |event| events_queue.push(event) } process_events end
Private Instance Methods
Source
# File lib/sequent/core/event_publisher.rb, line 63 def configuration Sequent.configuration end
Source
# File lib/sequent/core/event_publisher.rb, line 39 def events_queue Thread.current[:events_queue] ||= Queue.new end
Source
# File lib/sequent/core/event_publisher.rb, line 51 def process_event(event) fail ArgumentError, 'event is required' if event.nil? Sequent.logger.debug("[EventPublisher] Publishing event #{event.class}") if Sequent.logger.debug? configuration.event_handlers.each do |handler| handler.handle_message event rescue StandardError raise PublishEventError.new(handler.class, event) end end
Source
# File lib/sequent/core/event_publisher.rb, line 43 def process_events Sequent::Util.skip_if_already_processing(:events_queue_lock) do process_event(events_queue.pop) until events_queue.empty? ensure events_queue.clear end end