Skip to content

Instantly share code, notes, and snippets.

@jlecour
Created February 28, 2012 10:39
Show Gist options
  • Save jlecour/1931819 to your computer and use it in GitHub Desktop.
Save jlecour/1931819 to your computer and use it in GitHub Desktop.
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
@jlecour
Copy link
Author

jlecour commented Feb 28, 2012

I already many possible improvements :

  • using a more advanced logger
  • make it Rails/Bundler independant
  • daemonize it for real, and possible monitor it with God/Monit/…
  • format the data to help making graphs, …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment