Sha256: 4ce0b267dce5ff26e836f4e27d49f768033e71a9663aa8c1eb7aa09f4c5e4353
Contents?: true
Size: 1.42 KB
Versions: 7
Compression:
Stored size: 1.42 KB
Contents
#!/usr/bin/env ruby require 'optparse' require 'redis' require 'resque' require 'active_support/core_ext/hash/slice' require 'active_support/time' options = {} opt_parser = OptionParser.new do |opt| opt.banner = 'Usage: resque-status [OPTIONS]' opt.separator '' opt.separator 'Resque Status Tool' opt.separator '' opt.separator 'Options:' opt.on('-k', '--key [KEY]', 'resque info key, default pending') do |value| options[:key] = value end opt.on('-h', '--host HOST', 'redis host') do |value| options[:host] = value end opt.on('-p', '--port PORT', 'redis port') do |value| options[:port] = value end opt.on('-n', '--namespace NAMESPACE', 'redis namespace') do |value| options[:namespace] = value end opt.on('--help', 'help') do puts opt_parser exit end end opt_parser.parse! Resque.redis = Redis.new(options.slice(:host, :port)) Resque.redis.namespace = options.fetch(:namespace) info = Resque.info key = options.fetch(:key, :pending).to_sym if info.key?(key) puts info[key] elsif key == :oldest # oldest job work time in seconds workers = Resque.workers jobs = workers.map(&:job) worker_jobs = workers.zip(jobs).reject { |w, j| w.idle? || j['queue'].nil? } puts worker_jobs.map { |_, job| (Time.now.utc - DateTime.strptime(job['run_at'] ,'%Y-%m-%dT%H:%M:%S').utc).to_i }.max || 'null' else $stderr.puts "Unknown key. Should be one of the [#{info.keys.join(', ')}]" end
Version data entries
7 entries across 7 versions & 1 rubygems