DEV Community

Jorge Alvarez
Jorge Alvarez

Posted on

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more