Sha256: f13460119098a072e04d7e2029b7590ca5532dc0634fbb2925e0e99e5613e18b

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

class TableSync::Publishing::Batch
  include Tainbox

  attribute :object_class
  attribute :original_attributes

  attribute :routing_key
  attribute :headers

  attribute :event, default: :update

  def publish_later
    job.perform_later(job_attributes)
  end

  def publish_now
    message.publish
  end

  def message
    TableSync::Publishing::Message::Batch.new(attributes)
  end

  alias_method :publish_async, :publish_later

  private

  # JOB

  def job
    if TableSync.batch_publishing_job_class_callable
      TableSync.batch_publishing_job_class_callable.call
    else
      raise TableSync::NoCallableError.new("batch_publishing_job_class")
    end
  end

  def job_attributes
    attributes.merge(
      original_attributes: serialized_original_attributes,
    )
  end

  def serialized_original_attributes
    original_attributes.map do |set_of_attributes|
      TableSync::Publishing::Helpers::Attributes
        .new(set_of_attributes)
        .serialize
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
table_sync-6.4.0 lib/table_sync/publishing/batch.rb
table_sync-6.3.0 lib/table_sync/publishing/batch.rb
table_sync-6.1.0 lib/table_sync/publishing/batch.rb
table_sync-6.0.4 lib/table_sync/publishing/batch.rb
table_sync-6.0.3 lib/table_sync/publishing/batch.rb
table_sync-6.0.2 lib/table_sync/publishing/batch.rb
table_sync-6.0 lib/table_sync/publishing/batch.rb