rabbit-wq 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -1
- data/README.md +119 -7
- data/lib/rabbit_wq/cli.rb +3 -5
- data/lib/rabbit_wq/configuration.rb +1 -0
- data/lib/rabbit_wq/server.rb +20 -3
- data/lib/rabbit_wq/version.rb +1 -1
- metadata +2 -2
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
2.1.0
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
A work queue built on RabbitMQ and Celluloid.
|
4
4
|
|
5
|
-
This is NOT production ready. Released only to reserve gem name.
|
6
|
-
|
7
5
|
|
8
6
|
## Installation
|
9
7
|
|
@@ -22,7 +20,32 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
###
|
23
|
+
### Queue Subscriber
|
24
|
+
|
25
|
+
#### Starting the Work Queue Subscriber in Interactive Mode
|
26
|
+
|
27
|
+
$ rabbit-wq start --interactive
|
28
|
+
|
29
|
+
#### Starting the Work Queue Subscriber as a Daemon
|
30
|
+
|
31
|
+
$ rabbit-wq start
|
32
|
+
|
33
|
+
#### Stopping the Work Queue Subscriber
|
34
|
+
|
35
|
+
$ rabbit-wq stop
|
36
|
+
|
37
|
+
#### Restarting the Work Queue Subscriber
|
38
|
+
|
39
|
+
$ rabbit-wq restart
|
40
|
+
|
41
|
+
#### Checking the Status of the Work Queue Subscriber
|
42
|
+
|
43
|
+
$ rabbit-wq status
|
44
|
+
|
45
|
+
|
46
|
+
#### Queueing Work
|
47
|
+
|
48
|
+
#### Implementing as a PORO
|
26
49
|
|
27
50
|
class SomeWorker < Struct.new( :some_variable )
|
28
51
|
def call
|
@@ -33,15 +56,15 @@ Or install it yourself as:
|
|
33
56
|
worker = SomeWorker.new( 1 )
|
34
57
|
RabbitWQ::Work.enqueue( worker )
|
35
58
|
|
36
|
-
|
59
|
+
#### Work in the Future
|
37
60
|
|
38
61
|
RabbitWQ::Work.enqueue( worker, delay: 30000 )
|
39
62
|
|
40
|
-
|
63
|
+
#### Queueing Work with a Retry
|
41
64
|
|
42
65
|
RabbitWQ::Work.enqueue( worker, retry: 1 )
|
43
66
|
|
44
|
-
|
67
|
+
#### Queueing Work with a Retry and a Retry Delay
|
45
68
|
|
46
69
|
RabbitWQ::Work.enqueue( worker, retry: 1, retry_delay: 30000 )
|
47
70
|
|
@@ -52,7 +75,7 @@ Or install it yourself as:
|
|
52
75
|
Auto-scale will set up retries at the following intervals: 1 min, 5 mins, 15 mins, 30 mins,
|
53
76
|
1 hr, 6 hrs, 12 hrs, 24 hrs. and 48 hrs.
|
54
77
|
|
55
|
-
|
78
|
+
#### Implementing with the Worker Module
|
56
79
|
|
57
80
|
class SomeWorker < Struct.new( :some_variable )
|
58
81
|
include RabbitWQ::Worker
|
@@ -90,3 +113,92 @@ do not have to provide a refrence to self in this case.
|
|
90
113
|
end
|
91
114
|
|
92
115
|
The RabbitWQ loggers provide the following log levels: debug, info, warn, error and fatal.
|
116
|
+
|
117
|
+
### Configuration File
|
118
|
+
|
119
|
+
The RabbitWQ configuration file uses JSON syntax. The default location for the configuration file is /var/run/rabbit-wq/rabbit-wq.conf
|
120
|
+
|
121
|
+
Here is an example configuration file with each option's default value:
|
122
|
+
|
123
|
+
{
|
124
|
+
"delayed_exchange_prefix": "work-delay",
|
125
|
+
"delayed_queue_prefix": "work-delay",
|
126
|
+
"environment_file_path": nil,
|
127
|
+
"env": "production",
|
128
|
+
"error_queue": "work-error",
|
129
|
+
"threads": 1,
|
130
|
+
"time_zone": "UTC",
|
131
|
+
"work_exchange": "work",
|
132
|
+
"work_log_level": "info",
|
133
|
+
"work_log_path": "/var/log/rabbit-wq/rabbit-wq-work.log",
|
134
|
+
"work_queue": "work"
|
135
|
+
}
|
136
|
+
|
137
|
+
#### Options
|
138
|
+
|
139
|
+
#####delayed_exchange_prefix
|
140
|
+
The prefix for the delayed exchanges. Defaults to work-delay.
|
141
|
+
|
142
|
+
#####delayed_queue_prefix
|
143
|
+
The prefix for the delayed queues. Defaults to work-delay.
|
144
|
+
|
145
|
+
#####environment_file_path
|
146
|
+
The path to the environment file (loads all or some of application environment). No default.
|
147
|
+
|
148
|
+
#####env
|
149
|
+
The environment to run in. Defaults to production.
|
150
|
+
|
151
|
+
#####error_queue
|
152
|
+
The name of the error queue. Defaults to error.
|
153
|
+
|
154
|
+
#####threads
|
155
|
+
The size of the thread pool. Can be overridden with the command line option --threads or -t. Defaults to 1.
|
156
|
+
|
157
|
+
#####time_zone
|
158
|
+
The time zone to use with ActiveRecord.
|
159
|
+
|
160
|
+
#####work_exchange
|
161
|
+
The name of the work exchange. Defaults to work.
|
162
|
+
|
163
|
+
#####work_log_level
|
164
|
+
The log level of the worker logger. Defaults to info.
|
165
|
+
|
166
|
+
#####work_log_path
|
167
|
+
The path the worker logger will log to. Defaults to /var/log/rabbit-wq/rabbit-wq-work.log.
|
168
|
+
|
169
|
+
#####work_queue
|
170
|
+
The name of the work queue. Defaults to work.
|
171
|
+
|
172
|
+
|
173
|
+
### Command Line Interface
|
174
|
+
|
175
|
+
#### Commands
|
176
|
+
|
177
|
+
#####start
|
178
|
+
Starts the subscriber.
|
179
|
+
|
180
|
+
#####stop
|
181
|
+
Stops the subscriber.
|
182
|
+
|
183
|
+
#####restart
|
184
|
+
Restarts the subscriber.
|
185
|
+
|
186
|
+
#####status
|
187
|
+
Reports the status of the subscriber, started or stopped.
|
188
|
+
|
189
|
+
#### Options
|
190
|
+
|
191
|
+
#####config (--config or -c)
|
192
|
+
The path for the configuration file. Defaults to /etc/rabbit-wq/rabbit-wq.conf.
|
193
|
+
|
194
|
+
#####log_level (--log_level)
|
195
|
+
The log level for the work subscriber's logger. This does not have an effect on the worker logger. Defaults to info.
|
196
|
+
|
197
|
+
#####log (--log or -l)
|
198
|
+
The path for the work subsciber's log file. Defaults to /var/log/rabbit-wq/rabbit-wq.log.
|
199
|
+
|
200
|
+
#####pid (--pid)
|
201
|
+
The path to the PID file. Defaults to /var/run/rabbit-wq/rabbit-wq.pid.
|
202
|
+
|
203
|
+
#####interactive (--interactive or -i)
|
204
|
+
When used the work subscriber is executed in interactive (attached) mode as opposed to as a daemon.
|
data/lib/rabbit_wq/cli.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
2
|
require 'rabbit_wq'
|
3
3
|
require 'trollop'
|
4
4
|
require 'yell'
|
@@ -20,8 +20,6 @@ module RabbitWQ
|
|
20
20
|
DEFAULT_LOG_PATH = "/var/log/#{APP_ID}/#{APP_ID}.log"
|
21
21
|
DEFAULT_PID_PATH = "/var/run/#{APP_ID}/#{APP_ID}.pid"
|
22
22
|
|
23
|
-
DEFAULT_NUMBER_OF_THREADS = 1
|
24
|
-
|
25
23
|
def initialize( args )
|
26
24
|
Trollop::options do
|
27
25
|
version VERSION_COPYRIGHT
|
@@ -51,7 +49,7 @@ options:
|
|
51
49
|
opt :log_level, "The log level", :type => String, :default => 'info'
|
52
50
|
opt :log, "The path for the log file", :type => String, :short => '-l', :default => DEFAULT_LOG_PATH
|
53
51
|
opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH
|
54
|
-
opt :threads, "The number of threads", :type => Integer, :
|
52
|
+
opt :threads, "The number of threads", :type => Integer, :short => '-t'
|
55
53
|
end
|
56
54
|
when "start"
|
57
55
|
Trollop::options do
|
@@ -60,7 +58,7 @@ options:
|
|
60
58
|
opt :log_level, "The log level", :type => String, :default => 'info'
|
61
59
|
opt :log, "The path for the log file", :type => String, :short => '-l', :default => DEFAULT_LOG_PATH
|
62
60
|
opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH
|
63
|
-
opt :threads, "The number of threads", :type => Integer, :
|
61
|
+
opt :threads, "The number of threads", :type => Integer, :short => '-t'
|
64
62
|
end
|
65
63
|
when "status"
|
66
64
|
Trollop::options do
|
data/lib/rabbit_wq/server.rb
CHANGED
@@ -45,18 +45,20 @@ module RabbitWQ
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def pool
|
48
|
-
@pool ||= MessageHandler.pool( size:
|
48
|
+
@pool ||= MessageHandler.pool( size: threads )
|
49
49
|
end
|
50
50
|
|
51
51
|
def run
|
52
|
-
if
|
52
|
+
if threads == 1
|
53
53
|
Celluloid::Actor[:message_handler] = MessageHandler.new
|
54
54
|
end
|
55
55
|
|
56
|
+
info "threads: #{threads}"
|
57
|
+
|
56
58
|
@work_consumer = work_queue.subscribe( manual_ack: true ) do |delivery_info, metadata, payload|
|
57
59
|
info "LISTENER RECEIVED #{payload}"
|
58
60
|
|
59
|
-
if
|
61
|
+
if threads > 1
|
60
62
|
pool.async.call( payload: payload,
|
61
63
|
delivery_info: delivery_info,
|
62
64
|
metadata: metadata,
|
@@ -74,6 +76,10 @@ module RabbitWQ
|
|
74
76
|
Celluloid::Actor[:message_handler]
|
75
77
|
end
|
76
78
|
|
79
|
+
def threads
|
80
|
+
config.threads
|
81
|
+
end
|
82
|
+
|
77
83
|
def config
|
78
84
|
RabbitWQ.configuration
|
79
85
|
end
|
@@ -82,6 +88,7 @@ module RabbitWQ
|
|
82
88
|
load_configuration
|
83
89
|
initialize_loggers
|
84
90
|
load_environment
|
91
|
+
resolve_threads
|
85
92
|
end
|
86
93
|
|
87
94
|
def load_configuration
|
@@ -100,6 +107,16 @@ module RabbitWQ
|
|
100
107
|
require environment_file_path
|
101
108
|
end
|
102
109
|
|
110
|
+
def resolve_threads
|
111
|
+
if options[:threads]
|
112
|
+
RabbitWQ.configuration.threads = options[:threads]
|
113
|
+
end
|
114
|
+
|
115
|
+
return if RabbitWQ.configuration.threads
|
116
|
+
|
117
|
+
RabbitWQ.configuration.threads = 1
|
118
|
+
end
|
119
|
+
|
103
120
|
def environment_file_path
|
104
121
|
RabbitWQ.configuration.environment_file_path
|
105
122
|
end
|
data/lib/rabbit_wq/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit-wq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|