Skip to content

Instantly share code, notes, and snippets.

@hubrix
Forked from perplexes/Rakefile.rb
Created October 5, 2013 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubrix/6842431 to your computer and use it in GitHub Desktop.
Save hubrix/6842431 to your computer and use it in GitHub Desktop.
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