Sha256: ce8ddf267eee077ab22b703c34848cecb8f3c89748e44818bd83a3173fa85b93

Contents?: true

Size: 766 Bytes

Versions: 1

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

module UmbrellioUtils
  module Misc
    extend self

    def table_sync(scope, delay: 1, routing_key: nil)
      scope.in_batches do |batch|
        batch.each do |model|
          next if model.try(:skip_table_sync?)

          values = [model.class.name, model.values]
          publisher = TableSync::Publishing::Publisher.new(*values, confirm: false)
          publisher.routing_key = routing_key if routing_key
          publisher.publish_now
        end

        sleep delay
      end
    end

    # Ranges go from high to low priority
    def merge_ranges(*ranges)
      ranges = ranges.map { |x| x.present? && x.size == 2 ? x : [nil, nil] }
      ranges.first.zip(*ranges[1..]).map { |x| x.find(&:present?) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
umbrellio-utils-0.1.0 lib/umbrellio_utils/misc.rb