Skip to content

Commit f26934c

Browse files
tessrodefunkt
authored andcommitted
Accept namespaces in resque command
1 parent e19b83e commit f26934c

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

bin/resque

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
#!/usr/bin/env ruby
22

3-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4+
begin
5+
require 'redis-namespace'
6+
rescue LoadError
7+
require 'rubygems'
8+
require 'redis-namespace'
9+
end
410
require 'resque'
11+
require 'optparse'
12+
13+
parser = OptionParser.new do |opts|
14+
opts.banner = "Usage: resque [options] COMMAND"
15+
16+
opts.separator ""
17+
opts.separator "Options:"
18+
19+
opts.on("-r", "--redis [HOST:PORT]", "Redis connection string") do |host|
20+
Resque.redis = host
21+
end
22+
23+
opts.on("-N", "--namespace [NAMESPACE]", "Redis namespace") do |namespace|
24+
Resque.redis.namespace = namespace
25+
end
26+
27+
opts.on("-h", "--help", "Show this message") do
28+
puts opts
29+
exit
30+
end
31+
32+
opts.separator ""
33+
opts.separator "Commands:"
34+
opts.separator " remove WORKER Removes a worker"
35+
opts.separator " kill WORKER Kills a worker"
36+
opts.separator " list Lists known workers"
37+
end
538

639
def kill(worker)
740
abort "** resque kill WORKER_ID" if worker.nil?
@@ -34,11 +67,7 @@ def list
3467
end
3568
end
3669

37-
if (i = ARGV.index('-r')) && ARGV[i+1]
38-
Resque.redis = ARGV[i+1]
39-
ARGV.delete_at(i)
40-
ARGV.delete_at(i+1)
41-
end
70+
parser.parse!
4271

4372
case ARGV[0]
4473
when 'kill'
@@ -48,10 +77,5 @@ when 'remove'
4877
when 'list'
4978
list
5079
else
51-
puts "Usage: resque [-r redis_host:redis_port] COMMAND [option]"
52-
puts
53-
puts "Commands:"
54-
puts " remove WORKER Removes a worker"
55-
puts " kill WORKER Kills a worker"
56-
puts " list Lists known workers"
80+
puts parser.help
5781
end

0 commit comments

Comments
 (0)