Class: TableSync::Publishing::BatchPublisher

Inherits:
BasePublisher show all
Defined in:
lib/table_sync/publishing/batch_publisher.rb

Constant Summary

Constants inherited from BasePublisher

TableSync::Publishing::BasePublisher::BASE_SAFE_JSON_TYPES, TableSync::Publishing::BasePublisher::NOT_MAPPED

Instance Method Summary collapse

Constructor Details

#initialize(object_class, original_attributes_array, **options) ⇒ BatchPublisher

Returns a new instance of BatchPublisher.



4
5
6
7
8
9
10
11
12
13
14
15
# 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

Instance Method Details

#publishObject



17
18
19
# File 'lib/table_sync/publishing/batch_publisher.rb', line 17

def publish
  enqueue_job
end

#publish_nowObject



21
22
23
24
25
26
27
28
29
# 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