Created
February 28, 2012 10:39
-
-
Save jlecour/1931819 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
namespace :log_resque do | |
desc "Print out (every 2 seconds) the number of busy and total workers for Resque" | |
task :working do | |
# In your Rails app directory : | |
# bundle exec rake log_resque:working --silent >> log/resque_working.log & | |
interval = 2.0 | |
rails_env = ENV['RAILS_ENV'] || 'production' | |
root_dir = Pathname.new(__FILE__).dirname + '../../' | |
yaml_file = root_dir + 'config/redis.yml' | |
data = YAML.load_file(yaml_file) | |
redis_config = data.fetch(rails_env).fetch('resque').symbolize_keys | |
Resque.redis = Redis.connect(redis_config) | |
# log_device = root_dir + 'log/resque_working.log' | |
log_device = STDOUT | |
log_device.sync = true | |
logger = Logger.new(log_device) | |
loop do | |
start_time = Time.now | |
info = Resque.info | |
message = "#{Time.now.iso8601} #{info[:working]} #{info[:workers]}" | |
logger.info(message) | |
total_time = Time.now - start_time | |
sleep(interval - total_time) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I already many possible improvements :