-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run resque-status with CLI arguments
- Loading branch information
Showing
1 changed file
with
36 additions
and
20 deletions.
There are no files selected for viewing
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
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 |