Skip to content

Commit

Permalink
Run resque-status with CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Mar 31, 2015
1 parent 10906d6 commit 618418c
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions bin/resque-status
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
#!/usr/bin/env ruby
# coding: utf-8

# Скрипт для мониторинга состояния resque
require 'optparse'
require 'redis'
require 'resque'
require 'active_support/core_ext/hash/slice'

options = {}

opt_parser = OptionParser.new do |opt|
opt.banner = 'Usage: resque-status [OPTIONS]'
opt.separator ''
opt.separator 'Resque Status Tool'
opt.separator ''

require 'rubygems'
opt.separator 'Options:'

%w(oj yajl-ruby json gson).each do |library|
begin
gem(library) and break
rescue Gem::LoadError
# ignore, go to next adapter
opt.on('-k', '--key [KEY]', 'resque info key, default pending') do |value|
options[:key] = value
end
end

require 'resque'
require 'redis'
require 'resque/integration/configuration'
opt.on('-h', '--host HOST', 'redis host') do |value|
options[:host] = value
end

paths = File.join(Dir.pwd, 'config', 'resque.yml'),
File.join(Dir.pwd, 'config', 'resque.local.yml')
opt.on('-p', '--port PORT', 'redis port') do |value|
options[:port] = value
end

config = Resque::Integration::Configuration.new(*paths)
redis = config.redis
opt.on('-n', '--namespace NAMESPACE', 'redis namespace') do |value|
options[:namespace] = value
end

Resque.redis = Redis.new(redis)
Resque.redis.namespace = redis[:namespace]
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 = (ARGV.shift || :pending).to_sym
key = options.fetch(:key, :pending).to_sym

if info.key?(key)
puts info[key]
else
$stderr.puts "Unknown key. Should be one of the [#{info.keys.join(', ')}]"
end
end

0 comments on commit 618418c

Please sign in to comment.