class TableSync::Publishing::BatchPublisher
Attributes
event[R]
headers[R]
original_attributes_array[R]
routing_key[R]
Public Class Methods
new(object_class, original_attributes_array, **options)
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 4 def initialize(object_class, original_attributes_array, **options) @original_attributes_array = original_attributes_array.map do |hash| filter_safe_for_serialization(hash.deep_symbolize_keys) end @object_class = object_class.constantize @confirm = options[:confirm] || true @routing_key = options[:routing_key] || resolve_routing_key @push_original_attributes = options[:push_original_attributes] || false @headers = options[:headers] @event = options[:event] || :update end
Public Instance Methods
publish()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 17 def publish enqueue_job end
publish_now()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 21 def publish_now return unless need_publish? Rabbit.publish(params) model_naming = TableSync.publishing_adapter.model_naming(object_class) TableSync::Instrument.notify table: model_naming.table, schema: model_naming.schema, event: event, count: publishing_data[:attributes].size, direction: :publish end
Private Instance Methods
attributes_for_sync()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 86 def attributes_for_sync return original_attributes_array if push_original_attributes? objects.map do |object| if attributes_for_sync_defined? object.attributes_for_sync else TableSync.publishing_adapter.attributes(object) end end end
attrs_for_callables()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 55 def attrs_for_callables {} end
attrs_for_metadata()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 63 def attrs_for_metadata {} end
attrs_for_routing_key()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 59 def attrs_for_routing_key {} end
enqueue_additional_options()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 106 def enqueue_additional_options { confirm: confirm?, push_original_attributes: push_original_attributes? } end
enqueue_job()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 98 def enqueue_job job_class.perform_later( object_class.name, original_attributes_array, enqueue_additional_options, ) end
job_callable()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 47 def job_callable TableSync.batch_publishing_job_class_callable end
job_callable_error_message()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 51 def job_callable_error_message "Can't publish, set TableSync.batch_publishing_job_class_callable" end
need_publish?()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 39 def need_publish? (push_original_attributes? && original_attributes_array.present?) || objects.present? end
needles()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 74 def needles original_attributes_array.map { |original_attributes| original_attributes.slice(*primary_keys) } end
objects()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 43 def objects needles.map { |needle| TableSync.publishing_adapter.find(object_class, needle) }.compact end
params()
click to toggle source
Calls superclass method
TableSync::Publishing::BasePublisher#params
# File lib/table_sync/publishing/batch_publisher.rb, line 67 def params { **super, headers: headers, } end
publishing_data()
click to toggle source
Calls superclass method
TableSync::Publishing::BasePublisher#publishing_data
# File lib/table_sync/publishing/batch_publisher.rb, line 78 def publishing_data { **super, event: event, metadata: {}, } end
push_original_attributes?()
click to toggle source
# File lib/table_sync/publishing/batch_publisher.rb, line 35 def push_original_attributes? @push_original_attributes end