Created
March 21, 2012 23:19
-
-
Save treeder/2154083 to your computer and use it in GitHub Desktop.
Example of queuing up 100 workloads per task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users = User.all | |
users_for_worker = [] | |
users.each_with_index do |user, i| | |
# Queue up a task every 100 | |
if i > 0 && i % 100 == 0 | |
puts "#{i} Queueing worker..." | |
worker = NotificationWorker.new | |
worker.users = users_for_worker | |
# set other attributes that your worker needs to run | |
worker.queue | |
users_for_worker = [] | |
end | |
users_for_worker << user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment