class MixedGauge::AllShardsInParallel
Support parallel execution with each shard and deal with AR connection management in parallel execution.
Public Class Methods
new(shards, service:)
click to toggle source
@param [Array<Class>] shards An array of shard model class @param [Expeditor::Service] service
# File lib/mixed_gauge/all_shards_in_parallel.rb, line 7 def initialize(shards, service:) @shards = shards @service = service end
Public Instance Methods
each(&block)
click to toggle source
@yield [Class] A shard model class @return [MixedGauge::AllShardsInParallel] @example
User.all_shards_in_parallel.each {|m| puts m.count }
# File lib/mixed_gauge/all_shards_in_parallel.rb, line 36 def each(&block) map(&block) if block_given? self end
flat_map(&block)
click to toggle source
@yield [Class] A shard model class @return [Array] A result @example
User.all_shards_in_parallel.flat_map {|m| m.where(age: 1) }
# File lib/mixed_gauge/all_shards_in_parallel.rb, line 28 def flat_map(&block) map(&block).flatten end
map() { |m| ... }
click to toggle source
@yield [Class] A shard model class @return [Array] A result @example
User.all_shards_in_parallel.map(&:count).reduce(&:+)
# File lib/mixed_gauge/all_shards_in_parallel.rb, line 16 def map commands = @shards.map do |m| Expeditor::Command.new(service: @service) { m.connection_pool.with_connection { yield m } } end commands.each(&:start) commands.map(&:get) end