Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Last active August 29, 2015 14:05
Show Gist options
  • Save DanielVartanov/abff37b533a7d8c773d5 to your computer and use it in GitHub Desktop.
Save DanielVartanov/abff37b533a7d8c773d5 to your computer and use it in GitHub Desktop.
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