Module: DeployPin::ParallelWrapper

Included in:
Task, Task
Defined in:
lib/deploy_pin/parallel_wrapper.rb

Overview

Parallel wrapper to run parallel tasks using database statement timeout. This wrapper keeps parallel interface, but running the processes under db statement timeout.

In order to use this wrapper, just use call parallel methods with ‘parallel_`. Ex.:

parallel_each(1..2, in_processes: 2, timeout: 0.3.seconds) do |i|
  puts "Item: #{i}, Worker: #{Parallel.worker_number}"
  ActiveRecord::Base.connection.execute("<some db query>")
end

In order to pass more ‘timeout` options, it requires to pass an array, like:

parallel_each(1..2, in_processes: 2, timeout: [0.3.seconds, { connected_to: { role: :reading } }]) do |i|
  puts "Item: #{i}, Worker: #{Parallel.worker_number}"
  ActiveRecord::Base.connection.execute("<some db query>")
end

Defined Under Namespace

Classes: ParallelRunner

Constant Summary collapse

PARALLEL_PREFIX =
'parallel_'

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



74
75
76
77
78
# File 'lib/deploy_pin/parallel_wrapper.rb', line 74

def method_missing(name, *args, &block)
  return super unless respond_to_missing?(name)

  ParallelRunner.new(name, *args, &block).run
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

:reek:ManualDispatch and :reek:BooleanParameter

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'lib/deploy_pin/parallel_wrapper.rb', line 81

def respond_to_missing?(method_name, include_private = false)
  return super unless parallel_prefix_pattern.match? method_name

  parallel_method_name = method_name.to_s.gsub(PARALLEL_PREFIX, '').to_sym

  Parallel.respond_to?(parallel_method_name) || super
end