-
-
Save hubrix/6842431 to your computer and use it in GitHub Desktop.
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
task :workers => :environment do | |
module Delayed | |
class Worker | |
def name_with_thread_id(*a, &b) | |
name_without_thread_id(*a, &b) + " thread:#{Thread.current.object_id}" | |
end | |
alias_method_chain :name, :thread_id | |
end | |
end | |
Rails.logger.info "Running threaded worker env." | |
Delayed::Worker.lifecycle.around(:execute) do |*args, &block| | |
thread_num = (ActiveRecord::Base.connection_config[:pool] || 1) | |
threads = [] | |
Rails.logger.info "Using #{thread_num} threads for the worker." | |
thread_num.times do | |
threads << Thread.new(&block) | |
end | |
threads.each(&:join) | |
Rails.logger.info "End of threads." | |
end | |
Rake::Task["jobs:work"].execute | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment