DEV Community

Jorge Alvarez
Jorge Alvarez

Posted on

Find in batches and pluck

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

Top comments (0)