Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 并行线程_Ruby_Redis_Ruby On Rails 5_Sidekiq - Fatal编程技术网

Ruby 并行线程

Ruby 并行线程,ruby,redis,ruby-on-rails-5,sidekiq,Ruby,Redis,Ruby On Rails 5,Sidekiq,我使用sidekiq gem作为队列。我想在队列中并行处理我的执行 这是我的队列代码 def perform(disbursement_id) some logic... Parallel.each(disbursement.employee_disbursements, in_threads: 2) do |employee| amount = amount_format(employee.amount)

我使用sidekiq gem作为队列。我想在队列中并行处理我的执行

这是我的队列代码

      def perform(disbursement_id)
         some logic...
          Parallel.each(disbursement.employee_disbursements, in_threads: 2) do |employee|
            amount = amount_format(employee.amount)
            res = unload_company_account(cmp_acc_id, amount.to_s)
            load_employee_account(employee) unless res.empty?
          end
      end
现在,当我使用Parallel.each()而不使用线程时,它运行良好,但当我使用Parallel.each(..,in_threads:3)时,它将进入队列的繁忙状态


不确定为什么in_线程将我的队列置于繁忙状态。我无法解决此问题。

请尝试“下一步”使其正常工作

Parallel.each(disbursement.employee_disbursements, in_threads: 2) do |employee|
  ActiveRecord::Base.connection_pool.with_connection do
    amount = amount_format(employee.amount)
    res = unload_company_account(cmp_acc_id, amount.to_s)
    load_employee_account(employee) unless res.empty?
  end
end
此外,当使用map而不是each或pass属性时,这个问题就会消失。
preserve_results
true
false
。这有点神秘,因为:

def each(array, options={}, &block)
  map(array, options.merge(:preserve_results => false), &block)
end