Skip to content

Commit 4511d11

Browse files
author
Steven Li
committed
added cli arg support
1 parent 2b5bab7 commit 4511d11

9 files changed

+89
-20
lines changed

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# DisqueJockey
22
DisqueJockey is a fast, concurrent background job processing framework for the Disque message queue.
3-
# Getting Started
3+
4+
## Installation
45
First, you should run a Disque server if you aren't already doing so.
56
Disque source and build instructions can be found at: https://github.com/antirez/disque
67

@@ -48,10 +49,19 @@ Your worker class must do two things:
4849

4950
Lastly, you must place your worker in a directory named 'workers'
5051

51-
Once your worker is written and placed in a workers directory, you can call disque_jockey from the command line and it will start up your workers and begin delivering jobs to them.
52+
## Starting Disque Jockey
53+
Once your worker is written and placed in a workers directory,
54+
you can call `disque_jockey start` from the command line and it will
55+
start up your workers and begin delivering jobs to them.
56+
57+
To see all the command line options, use the help command
58+
```
59+
disque_jockey help start
60+
```
5261

62+
To start disque_jockey with the desired options
5363
````
54-
disque_jockey
64+
disque_jockey start --env=production --daemonize=true --worker-groups=10 --nodes=127.0.0.1:7111,34.45.231.124:4242
5565
````
5666

5767
Messages successfully handled by a worker (ie no exceptions raised from the handle method) will be acknowledged and removed from the queue.
@@ -61,6 +71,5 @@ DisqueJockey is not a currently a production-ready system, and there are a numbe
6171
Here is a list of functionality I'd like to add to DisqueJockey in the near future:
6272
- Allow workers to set auto-acknowledge or fast-acknowledge of messages.
6373
- Better test coverage around worker groups
64-
- Command line options (e.g. environment)
6574
- Rails integration (ActiveJob Adapter)
6675
- More use cases in the README (e.g. how to use alongside Rails)

bin/disque_jockey

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
22

3+
$:.unshift(File.expand_path("../../lib", __FILE__))
4+
35
require 'disque_jockey'
4-
DisqueJockey.run!
6+
DisqueJockey::CLI.start(ARGV)

disque_jockey.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
1919
gem.require_paths = ['lib']
2020
gem.add_runtime_dependency 'disque'
2121
gem.add_runtime_dependency 'logging'
22+
gem.add_runtime_dependency 'thor'
2223
gem.add_development_dependency('rspec', '~> 3.1', '>= 3.0')
2324
gem.add_development_dependency('rake')
2425
gem.add_development_dependency('pry')

lib/disque_jockey.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'disque_jockey/version'
2+
require 'disque_jockey/cli/help'
3+
require 'disque_jockey/cli'
24
require 'disque_jockey/exceptions'
35
require 'disque_jockey/broker'
46
require 'disque_jockey/logger'
@@ -9,7 +11,6 @@
911
require 'disque_jockey/worker_group'
1012
require 'timeout'
1113

12-
1314
module DisqueJockey
1415
# raise exceptions in all threads so we don't fail silently
1516
Thread.abort_on_exception = true
@@ -22,7 +23,10 @@ def self.configure
2223
yield(self.configuration)
2324
end
2425

25-
def self.run!
26+
def self.run!(options)
27+
@configuration = DisqueJockey::Configuration.new(options)
28+
2629
DisqueJockey::Supervisor.work!
2730
end
28-
end
31+
end
32+

lib/disque_jockey/cli.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require "thor"
2+
3+
module DisqueJockey
4+
class CLI < Thor
5+
desc "start", "Start disque_jockey"
6+
option :env, :desc => "set environment"
7+
option :worker_groups, :desc => "set number of worker groups"
8+
option :log_path, :desc => "set path to logs"
9+
option :nodes, :desc => "set nodes"
10+
option :daemonize, :type => :boolean, :desc => "run disque_jockey as daemon"
11+
long_desc DisqueJockey::CLI::Help.start
12+
13+
def start
14+
DisqueJockey.run!(options)
15+
end
16+
end
17+
end
18+

lib/disque_jockey/cli/help.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "thor"
2+
3+
module DisqueJockey
4+
class CLI < Thor
5+
class Help
6+
class << self
7+
def start
8+
<<-EOL
9+
Starts disque_jockey processes to start processing Disque jobs.
10+
11+
Examples:
12+
13+
$ disque_jockey start --env=production
14+
15+
$ disque_jockey start --env=development --daemonize=true --work-groups=5
16+
17+
$ disque_jockey start --nodes=127.0.0.1:6534,54.634.23.43:3452,546.23.124.34:4353
18+
EOL
19+
end
20+
end
21+
end
22+
end
23+
end
24+

lib/disque_jockey/configuration.rb

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
module DisqueJockey
22
class Configuration
33

4-
attr_accessor :logger, :worker_groups, :log_path, :env, :nodes
4+
attr_accessor :logger, :worker_groups, :log_path, :env, :nodes, :daemonize
55

6-
def initialize
7-
# set defaults
8-
@worker_groups = 2
9-
@log_path = (env == 'test' ? 'spec/log' : 'log')
10-
@nodes = ["127.0.0.1:7711"]
6+
def initialize(options={})
7+
@env = options["env"] || ENV["DISQUE_JOCKEY_ENV"] || "development"
8+
@worker_groups = options["worker_groups"] || 2
9+
@log_path = options["log_path"] || log_path_default
10+
@nodes = parse_nodes(options["nodes"]) || ["127.0.0.1:7711"]
11+
@daemonize = options["daemonize"] || daemonize_default
1112
end
1213

13-
def env
14-
@env ||= ENV['DISQUE_JOCKEY_ENV'] || 'development'
14+
def daemonize?
15+
@daemonize
1516
end
1617

17-
def daemonize?
18-
env != 'development'
18+
private
19+
20+
def parse_nodes(nodes)
21+
return unless nodes
22+
nodes.split(",")
1923
end
2024

25+
def log_path_default
26+
env == "test" ? "spec/log" : "log"
27+
end
28+
29+
def daemonize_default
30+
env != 'development'
31+
end
2132
end
2233
end
2334

lib/disque_jockey/supervisor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ def self.trap_signals_in_parent
8282

8383

8484
end
85-
end
85+
end

lib/disque_jockey/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module DisqueJockey
2-
VERSION = '0.0.1'
2+
VERSION = '0.0.2'
33
end

0 commit comments

Comments
 (0)