Find in batches and pluck

Jorge Alvarez - Jan 2 - - Dev Community

How to use find in batches in Ruby on Rails along with pluck.

class NewYearJob
  def perform
    Employee.active.in_batches do |employees|
      rotate_jobs = employees.pluck(:id).map do |employee_id|
        RotateYearJob.new(employee_id)
      end

      ActiveJob.perform_all_later(rotate_jobs)
    end
  end
end
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . .