Last active
August 29, 2015 14:05
-
-
Save DanielVartanov/abff37b533a7d8c773d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
MAX_THREADS_PER_ACCOUNT = 5 | |
common_job_queue = ... | |
loop do | |
registered_accounts.each do |account| | |
account_jobs = common_job_queue.extract_account_jobs(account) | |
account_jobs.each_slice(MAX_THREADS_PER_ACCOUNT) do |batch| | |
threads = batch.map do |job| | |
Thread.new do | |
job.perform | |
end | |
end | |
threads.each(&:join) | |
account.perform_magic_after_each_N_jobs | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment