Class: Dionysus::Producer::Outbox::Publisher
- Inherits:
-
Object
- Object
- Dionysus::Producer::Outbox::Publisher
- Defined in:
- lib/dionysus/producer/outbox/publisher.rb
Instance Method Summary collapse
-
#initialize(config:) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(outbox_record, options = {}) ⇒ Object
- #publish_observers(outbox_record) ⇒ Object
Constructor Details
#initialize(config:) ⇒ Publisher
Returns a new instance of Publisher.
7 8 9 |
# File 'lib/dionysus/producer/outbox/publisher.rb', line 7 def initialize(config:) @config = config end |
Instance Method Details
#publish(outbox_record, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dionysus/producer/outbox/publisher.rb', line 11 def publish(outbox_record, = {}) return if Dionysus::Producer::Suppressor.suppressed? with_consistent_reads do instrument("publishing_with_dionysus") do resource_class = outbox_record.resource_class.constantize primary_key = resource_class.primary_key primary_key_value = outbox_record.resource_id topic = outbox_record.topic resource = resource_class.find_by(primary_key => primary_key_value) || resource_class.new(primary_key => primary_key_value) event_name = outbox_record.event_name if resource.new_record? && outbox_record.created_event? logger.error( "Attempted to publish #{resource.class}, id: #{resource.id} but it was deleted, that should never happen!" ) return end if resource.new_record? && outbox_record.updated_event? logger.error( "There was an update of #{resource.class}, id: #{resource.id} but it was deleted, that should never happen!" ) return end published_count = publish_for_top_level_resource(outbox_record, resource, event_name, topic, ) + publish_for_dependency(resource, topic, ) handle_nothing_published(resource, event_name, topic) if published_count.zero? published_count end end end |
#publish_observers(outbox_record) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dionysus/producer/outbox/publisher.rb', line 45 def publish_observers(outbox_record) return if Dionysus::Producer::Suppressor.suppressed? with_consistent_reads do instrument("publishing_observers_with_dionysus") do resource_class = outbox_record.resource_class.constantize primary_key = resource_class.primary_key primary_key_value = outbox_record.resource_id resource = resource_class.find_by(primary_key => primary_key_value) || resource_class.new(primary_key => primary_key_value) changeset = outbox_record.transformed_changeset Dionysus::Producer.observers_with_responders_for(resource, changeset).each do |observers, responder| if observers.count > config.observers_inline_maximum_size execute_genesis_for_observers(observers, responder) else observers.each { |observer_record| publish_observer(observer_record, responder) } end end end end end |