qs 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/qs/daemon.rb +44 -4
- data/lib/qs/daemon_data.rb +18 -11
- data/lib/qs/process.rb +1 -2
- data/lib/qs/version.rb +1 -1
- data/qs.gemspec +1 -1
- data/test/unit/daemon_data_tests.rb +37 -19
- data/test/unit/daemon_tests.rb +114 -21
- data/test/unit/process_tests.rb +5 -16
- metadata +8 -8
data/lib/qs/daemon.rb
CHANGED
@@ -63,6 +63,10 @@ module Qs
|
|
63
63
|
@daemon_data.name
|
64
64
|
end
|
65
65
|
|
66
|
+
def process_label
|
67
|
+
@daemon_data.process_label
|
68
|
+
end
|
69
|
+
|
66
70
|
def pid_file
|
67
71
|
@daemon_data.pid_file
|
68
72
|
end
|
@@ -129,10 +133,19 @@ module Qs
|
|
129
133
|
self.daemon_data.min_workers,
|
130
134
|
self.daemon_data.max_workers
|
131
135
|
){ |queue_item| process(queue_item) }
|
136
|
+
|
137
|
+
# add internal callbacks
|
132
138
|
wp.on_worker_error do |worker, exception, queue_item|
|
133
139
|
handle_worker_exception(exception, queue_item)
|
134
140
|
end
|
135
141
|
wp.on_worker_sleep{ @worker_available_io.write(SIGNAL) }
|
142
|
+
|
143
|
+
# add any configured callbacks
|
144
|
+
self.daemon_data.worker_start_procs.each{ |cb| wp.on_worker_start(&cb) }
|
145
|
+
self.daemon_data.worker_shutdown_procs.each{ |cb| wp.on_worker_shutdown(&cb) }
|
146
|
+
self.daemon_data.worker_sleep_procs.each{ |cb| wp.on_worker_sleep(&cb) }
|
147
|
+
self.daemon_data.worker_wakeup_procs.each{ |cb| wp.on_worker_wakeup(&cb) }
|
148
|
+
|
136
149
|
wp.start
|
137
150
|
wp
|
138
151
|
end
|
@@ -246,6 +259,22 @@ module Qs
|
|
246
259
|
self.max_workers(*args)
|
247
260
|
end
|
248
261
|
|
262
|
+
def on_worker_start(&block)
|
263
|
+
self.configuration.worker_start_procs << block
|
264
|
+
end
|
265
|
+
|
266
|
+
def on_worker_shutdown(&block)
|
267
|
+
self.configuration.worker_shutdown_procs << block
|
268
|
+
end
|
269
|
+
|
270
|
+
def on_worker_sleep(&block)
|
271
|
+
self.configuration.worker_sleep_procs << block
|
272
|
+
end
|
273
|
+
|
274
|
+
def on_worker_wakeup(&block)
|
275
|
+
self.configuration.worker_wakeup_procs << block
|
276
|
+
end
|
277
|
+
|
249
278
|
def verbose_logging(*args)
|
250
279
|
self.configuration.verbose_logging(*args)
|
251
280
|
end
|
@@ -286,14 +315,20 @@ module Qs
|
|
286
315
|
|
287
316
|
option :shutdown_timeout
|
288
317
|
|
318
|
+
attr_accessor :process_label
|
289
319
|
attr_accessor :init_procs, :error_procs
|
290
320
|
attr_accessor :queues
|
321
|
+
attr_reader :worker_start_procs, :worker_shutdown_procs
|
322
|
+
attr_reader :worker_sleep_procs, :worker_wakeup_procs
|
291
323
|
|
292
324
|
def initialize(values = nil)
|
293
325
|
super(values)
|
326
|
+
@process_label = !(v = ENV['QS_PROCESS_LABEL'].to_s).empty? ? v : self.name
|
294
327
|
@init_procs, @error_procs = [], []
|
328
|
+
@worker_start_procs, @worker_shutdown_procs = [], []
|
329
|
+
@worker_sleep_procs, @worker_wakeup_procs = [], []
|
295
330
|
@queues = []
|
296
|
-
@valid
|
331
|
+
@valid = nil
|
297
332
|
end
|
298
333
|
|
299
334
|
def routes
|
@@ -302,9 +337,14 @@ module Qs
|
|
302
337
|
|
303
338
|
def to_hash
|
304
339
|
super.merge({
|
305
|
-
:
|
306
|
-
:
|
307
|
-
:
|
340
|
+
:process_label => self.process_label,
|
341
|
+
:error_procs => self.error_procs,
|
342
|
+
:worker_start_procs => self.worker_start_procs,
|
343
|
+
:worker_shutdown_procs => self.worker_shutdown_procs,
|
344
|
+
:worker_sleep_procs => self.worker_sleep_procs,
|
345
|
+
:worker_wakeup_procs => self.worker_wakeup_procs,
|
346
|
+
:routes => self.routes,
|
347
|
+
:queue_redis_keys => self.queues.map(&:redis_key)
|
308
348
|
})
|
309
349
|
end
|
310
350
|
|
data/lib/qs/daemon_data.rb
CHANGED
@@ -7,9 +7,11 @@ module Qs
|
|
7
7
|
# options one time here and memoize their values. This way, we don't pay the
|
8
8
|
# NsOptions overhead when reading them while handling a message.
|
9
9
|
|
10
|
-
attr_reader :name
|
10
|
+
attr_reader :name, :process_label
|
11
11
|
attr_reader :pid_file
|
12
12
|
attr_reader :min_workers, :max_workers
|
13
|
+
attr_reader :worker_start_procs, :worker_shutdown_procs
|
14
|
+
attr_reader :worker_sleep_procs, :worker_wakeup_procs
|
13
15
|
attr_reader :logger, :verbose_logging
|
14
16
|
attr_reader :shutdown_timeout
|
15
17
|
attr_reader :error_procs
|
@@ -17,16 +19,21 @@ module Qs
|
|
17
19
|
|
18
20
|
def initialize(args = nil)
|
19
21
|
args ||= {}
|
20
|
-
@name
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
22
|
+
@name = args[:name]
|
23
|
+
@process_label = args[:process_label]
|
24
|
+
@pid_file = args[:pid_file]
|
25
|
+
@min_workers = args[:min_workers]
|
26
|
+
@max_workers = args[:max_workers]
|
27
|
+
@worker_start_procs = args[:worker_start_procs]
|
28
|
+
@worker_shutdown_procs = args[:worker_shutdown_procs]
|
29
|
+
@worker_sleep_procs = args[:worker_sleep_procs]
|
30
|
+
@worker_wakeup_procs = args[:worker_wakeup_procs]
|
31
|
+
@logger = args[:logger]
|
32
|
+
@verbose_logging = !!args[:verbose_logging]
|
33
|
+
@shutdown_timeout = args[:shutdown_timeout]
|
34
|
+
@error_procs = args[:error_procs] || []
|
35
|
+
@queue_redis_keys = args[:queue_redis_keys] || []
|
36
|
+
@routes = build_routes(args[:routes] || [])
|
30
37
|
end
|
31
38
|
|
32
39
|
def route_for(route_id)
|
data/lib/qs/process.rb
CHANGED
@@ -17,8 +17,7 @@ module Qs
|
|
17
17
|
def initialize(daemon, options = nil)
|
18
18
|
options ||= {}
|
19
19
|
@daemon = daemon
|
20
|
-
|
21
|
-
@name = "qs: #{process_label}"
|
20
|
+
@name = "qs: #{@daemon.process_label}"
|
22
21
|
@logger = @daemon.logger
|
23
22
|
|
24
23
|
@pid_file = PIDFile.new(@daemon.pid_file)
|
data/lib/qs/version.rb
CHANGED
data/qs.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_dependency("ns-options", ["~> 1.1"])
|
24
24
|
gem.add_dependency("SystemTimer", ["~> 1.2"])
|
25
25
|
|
26
|
-
gem.add_development_dependency("assert", ["~> 2.
|
26
|
+
gem.add_development_dependency("assert", ["~> 2.15"])
|
27
27
|
gem.add_development_dependency("scmd", ["~> 2.3"])
|
28
28
|
end
|
@@ -9,37 +9,50 @@ class Qs::DaemonData
|
|
9
9
|
class UnitTests < Assert::Context
|
10
10
|
desc "Qs::DaemonData"
|
11
11
|
setup do
|
12
|
-
@name
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
12
|
+
@name = Factory.string
|
13
|
+
@process_label = Factory.string
|
14
|
+
@pid_file = Factory.file_path
|
15
|
+
@min_workers = Factory.integer
|
16
|
+
@max_workers = Factory.integer
|
17
|
+
@start_procs = Factory.integer(3).times.map{ proc{} }
|
18
|
+
@shutdown_procs = Factory.integer(3).times.map{ proc{} }
|
19
|
+
@sleep_procs = Factory.integer(3).times.map{ proc{} }
|
20
|
+
@wakeup_procs = Factory.integer(3).times.map{ proc{} }
|
21
|
+
@logger = Factory.string
|
22
|
+
@verbose_logging = Factory.boolean
|
18
23
|
@shutdown_timeout = Factory.integer
|
19
|
-
@error_procs
|
20
|
-
@queue_redis_keys =
|
24
|
+
@error_procs = [ proc{ Factory.string } ]
|
25
|
+
@queue_redis_keys = Factory.integer(3).times.map{ Factory.string }
|
26
|
+
|
21
27
|
@routes = (0..Factory.integer(3)).map do
|
22
28
|
Qs::Route.new(Factory.string, TestHandler.to_s).tap(&:validate!)
|
23
29
|
end
|
24
30
|
|
25
31
|
@daemon_data = Qs::DaemonData.new({
|
26
|
-
:name
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
32
|
+
:name => @name,
|
33
|
+
:process_label => @process_label,
|
34
|
+
:pid_file => @pid_file,
|
35
|
+
:min_workers => @min_workers,
|
36
|
+
:max_workers => @max_workers,
|
37
|
+
:worker_start_procs => @start_procs,
|
38
|
+
:worker_shutdown_procs => @shutdown_procs,
|
39
|
+
:worker_sleep_procs => @sleep_procs,
|
40
|
+
:worker_wakeup_procs => @wakeup_procs,
|
41
|
+
:logger => @logger,
|
42
|
+
:verbose_logging => @verbose_logging,
|
43
|
+
:shutdown_timeout => @shutdown_timeout,
|
44
|
+
:error_procs => @error_procs,
|
45
|
+
:queue_redis_keys => @queue_redis_keys,
|
46
|
+
:routes => @routes
|
36
47
|
})
|
37
48
|
end
|
38
49
|
subject{ @daemon_data }
|
39
50
|
|
40
|
-
should have_readers :name
|
51
|
+
should have_readers :name, :process_label
|
41
52
|
should have_readers :pid_file
|
42
53
|
should have_readers :min_workers, :max_workers
|
54
|
+
should have_readers :worker_start_procs, :worker_shutdown_procs
|
55
|
+
should have_readers :worker_sleep_procs, :worker_wakeup_procs
|
43
56
|
should have_readers :logger, :verbose_logging
|
44
57
|
should have_readers :shutdown_timeout
|
45
58
|
should have_readers :error_procs
|
@@ -48,9 +61,14 @@ class Qs::DaemonData
|
|
48
61
|
|
49
62
|
should "know its attributes" do
|
50
63
|
assert_equal @name, subject.name
|
64
|
+
assert_equal @process_label, subject.process_label
|
51
65
|
assert_equal @pid_file, subject.pid_file
|
52
66
|
assert_equal @min_workers, subject.min_workers
|
53
67
|
assert_equal @max_workers, subject.max_workers
|
68
|
+
assert_equal @start_procs, subject.worker_start_procs
|
69
|
+
assert_equal @shutdown_procs, subject.worker_shutdown_procs
|
70
|
+
assert_equal @sleep_procs, subject.worker_sleep_procs
|
71
|
+
assert_equal @wakeup_procs, subject.worker_wakeup_procs
|
54
72
|
assert_equal @logger, subject.logger
|
55
73
|
assert_equal @verbose_logging, subject.verbose_logging
|
56
74
|
assert_equal @shutdown_timeout, subject.shutdown_timeout
|
data/test/unit/daemon_tests.rb
CHANGED
@@ -20,6 +20,8 @@ module Qs::Daemon
|
|
20
20
|
should have_imeths :configuration
|
21
21
|
should have_imeths :name, :pid_file
|
22
22
|
should have_imeths :min_workers, :max_workers, :workers
|
23
|
+
should have_imeths :on_worker_start, :on_worker_shutdown
|
24
|
+
should have_imeths :on_worker_sleep, :on_worker_wakeup
|
23
25
|
should have_imeths :verbose_logging, :logger
|
24
26
|
should have_imeths :shutdown_timeout
|
25
27
|
should have_imeths :init, :error, :queue
|
@@ -68,6 +70,22 @@ module Qs::Daemon
|
|
68
70
|
assert_equal new_workers, subject.max_workers
|
69
71
|
end
|
70
72
|
|
73
|
+
should "allow reading/writing its configuration worker procs" do
|
74
|
+
p = proc{}
|
75
|
+
|
76
|
+
subject.on_worker_start(&p)
|
77
|
+
assert_equal [p], subject.configuration.worker_start_procs
|
78
|
+
|
79
|
+
subject.on_worker_shutdown(&p)
|
80
|
+
assert_equal [p], subject.configuration.worker_shutdown_procs
|
81
|
+
|
82
|
+
subject.on_worker_sleep(&p)
|
83
|
+
assert_equal [p], subject.configuration.worker_sleep_procs
|
84
|
+
|
85
|
+
subject.on_worker_wakeup(&p)
|
86
|
+
assert_equal [p], subject.configuration.worker_wakeup_procs
|
87
|
+
end
|
88
|
+
|
71
89
|
should "allow reading/writing its configuration verbose logging" do
|
72
90
|
new_verbose = Factory.boolean
|
73
91
|
subject.verbose_logging(new_verbose)
|
@@ -114,16 +132,26 @@ module Qs::Daemon
|
|
114
132
|
@qs_init_called = false
|
115
133
|
Assert.stub(Qs, :init){ @qs_init_called = true }
|
116
134
|
|
117
|
-
@queue = Qs::Queue.new do
|
118
|
-
name(Factory.string)
|
119
|
-
job 'test', TestHandler.to_s
|
120
|
-
end
|
121
135
|
@daemon_class.name Factory.string
|
122
136
|
@daemon_class.pid_file Factory.file_path
|
123
137
|
@daemon_class.workers Factory.integer
|
124
138
|
@daemon_class.verbose_logging Factory.boolean
|
125
139
|
@daemon_class.shutdown_timeout Factory.integer
|
126
140
|
@daemon_class.error{ Factory.string }
|
141
|
+
|
142
|
+
@start_procs = Factory.integer(3).times.map{ proc{} }
|
143
|
+
@shutdown_procs = Factory.integer(3).times.map{ proc{} }
|
144
|
+
@sleep_procs = Factory.integer(3).times.map{ proc{} }
|
145
|
+
@wakeup_procs = Factory.integer(3).times.map{ proc{} }
|
146
|
+
@start_procs.each { |p| @daemon_class.on_worker_start(&p) }
|
147
|
+
@shutdown_procs.each { |p| @daemon_class.on_worker_shutdown(&p) }
|
148
|
+
@sleep_procs.each { |p| @daemon_class.on_worker_sleep(&p) }
|
149
|
+
@wakeup_procs.each { |p| @daemon_class.on_worker_wakeup(&p) }
|
150
|
+
|
151
|
+
@queue = Qs::Queue.new do
|
152
|
+
name(Factory.string)
|
153
|
+
job 'test', TestHandler.to_s
|
154
|
+
end
|
127
155
|
@daemon_class.queue @queue
|
128
156
|
|
129
157
|
@client_spy = nil
|
@@ -148,13 +176,19 @@ module Qs::Daemon
|
|
148
176
|
class InitTests < InitSetupTests
|
149
177
|
desc "when init"
|
150
178
|
setup do
|
179
|
+
@current_env_process_label = ENV['QS_PROCESS_LABEL']
|
180
|
+
ENV['QS_PROCESS_LABEL'] = Factory.string
|
181
|
+
|
151
182
|
@daemon = @daemon_class.new
|
152
183
|
end
|
184
|
+
teardown do
|
185
|
+
ENV['QS_PROCESS_LABEL'] = @current_env_process_label
|
186
|
+
end
|
153
187
|
subject{ @daemon }
|
154
188
|
|
155
189
|
should have_readers :daemon_data, :logger
|
156
190
|
should have_readers :signals_redis_key, :queue_redis_keys
|
157
|
-
should have_imeths :name, :pid_file
|
191
|
+
should have_imeths :name, :process_label, :pid_file
|
158
192
|
should have_imeths :running?
|
159
193
|
should have_imeths :start, :stop, :halt
|
160
194
|
|
@@ -171,15 +205,24 @@ module Qs::Daemon
|
|
171
205
|
data = subject.daemon_data
|
172
206
|
|
173
207
|
assert_instance_of Qs::DaemonData, data
|
174
|
-
assert_equal configuration.name,
|
175
|
-
assert_equal configuration.
|
176
|
-
assert_equal configuration.
|
177
|
-
assert_equal configuration.
|
208
|
+
assert_equal configuration.name, data.name
|
209
|
+
assert_equal configuration.process_label, data.process_label
|
210
|
+
assert_equal configuration.pid_file, data.pid_file
|
211
|
+
assert_equal configuration.min_workers, data.min_workers
|
212
|
+
assert_equal configuration.max_workers, data.max_workers
|
213
|
+
|
214
|
+
assert_equal configuration.worker_start_procs, data.worker_start_procs
|
215
|
+
assert_equal configuration.worker_shutdown_procs, data.worker_shutdown_procs
|
216
|
+
assert_equal configuration.worker_sleep_procs, data.worker_sleep_procs
|
217
|
+
assert_equal configuration.worker_wakeup_procs, data.worker_wakeup_procs
|
218
|
+
|
178
219
|
assert_equal configuration.verbose_logging, data.verbose_logging
|
179
220
|
assert_equal configuration.shutdown_timeout, data.shutdown_timeout
|
180
221
|
assert_equal configuration.error_procs, data.error_procs
|
181
|
-
|
222
|
+
|
223
|
+
assert_equal [@queue.redis_key], data.queue_redis_keys
|
182
224
|
assert_equal configuration.routes, data.routes.values
|
225
|
+
|
183
226
|
assert_instance_of configuration.logger.class, data.logger
|
184
227
|
end
|
185
228
|
|
@@ -190,10 +233,11 @@ module Qs::Daemon
|
|
190
233
|
assert_equal data.queue_redis_keys, subject.queue_redis_keys
|
191
234
|
end
|
192
235
|
|
193
|
-
should "know its name and pid file" do
|
236
|
+
should "know its name, process label and pid file" do
|
194
237
|
data = subject.daemon_data
|
195
|
-
assert_equal data.name,
|
196
|
-
assert_equal data.
|
238
|
+
assert_equal data.name, subject.name
|
239
|
+
assert_equal data.process_label, subject.process_label
|
240
|
+
assert_equal data.pid_file, subject.pid_file
|
197
241
|
end
|
198
242
|
|
199
243
|
should "build a client" do
|
@@ -242,8 +286,22 @@ module Qs::Daemon
|
|
242
286
|
assert_not_nil @worker_pool_spy
|
243
287
|
assert_equal @daemon_class.min_workers, @worker_pool_spy.min_workers
|
244
288
|
assert_equal @daemon_class.max_workers, @worker_pool_spy.max_workers
|
245
|
-
|
246
|
-
|
289
|
+
|
290
|
+
exp = 1
|
291
|
+
assert_equal exp, @worker_pool_spy.on_worker_error_callbacks.size
|
292
|
+
|
293
|
+
exp = @start_procs.size
|
294
|
+
assert_equal exp, @worker_pool_spy.on_worker_start_callbacks.size
|
295
|
+
|
296
|
+
exp = @shutdown_procs.size
|
297
|
+
assert_equal exp, @worker_pool_spy.on_worker_shutdown_callbacks.size
|
298
|
+
|
299
|
+
exp = @sleep_procs.size + 1 # configured plus 1 internal
|
300
|
+
assert_equal exp, @worker_pool_spy.on_worker_sleep_callbacks.size
|
301
|
+
|
302
|
+
exp = @wakeup_procs.size
|
303
|
+
assert_equal exp, @worker_pool_spy.on_worker_wakeup_callbacks.size
|
304
|
+
|
247
305
|
assert_true @worker_pool_spy.start_called
|
248
306
|
end
|
249
307
|
|
@@ -549,8 +607,11 @@ module Qs::Daemon
|
|
549
607
|
should have_options :min_workers, :max_workers
|
550
608
|
should have_options :verbose_logging, :logger
|
551
609
|
should have_options :shutdown_timeout
|
610
|
+
should have_accessors :process_label
|
552
611
|
should have_accessors :init_procs, :error_procs
|
553
612
|
should have_accessors :queues
|
613
|
+
should have_readers :worker_start_procs, :worker_shutdown_procs
|
614
|
+
should have_readers :worker_sleep_procs, :worker_wakeup_procs
|
554
615
|
should have_imeths :routes
|
555
616
|
should have_imeths :to_hash
|
556
617
|
should have_imeths :valid?, :validate!
|
@@ -559,7 +620,7 @@ module Qs::Daemon
|
|
559
620
|
assert_includes NsOptions::Proxy, subject.class
|
560
621
|
end
|
561
622
|
|
562
|
-
should "default its options" do
|
623
|
+
should "default its options and attrs" do
|
563
624
|
config = Configuration.new
|
564
625
|
assert_nil config.name
|
565
626
|
assert_nil config.pid_file
|
@@ -568,12 +629,36 @@ module Qs::Daemon
|
|
568
629
|
assert_true config.verbose_logging
|
569
630
|
assert_instance_of Qs::NullLogger, config.logger
|
570
631
|
assert_nil subject.shutdown_timeout
|
632
|
+
|
633
|
+
assert_nil config.process_label
|
571
634
|
assert_equal [], config.init_procs
|
572
635
|
assert_equal [], config.error_procs
|
636
|
+
assert_equal [], subject.worker_start_procs
|
637
|
+
assert_equal [], subject.worker_shutdown_procs
|
638
|
+
assert_equal [], subject.worker_sleep_procs
|
639
|
+
assert_equal [], subject.worker_wakeup_procs
|
573
640
|
assert_equal [], config.queues
|
574
641
|
assert_equal [], config.routes
|
575
642
|
end
|
576
643
|
|
644
|
+
should "prefer an env var for the label but fall back to the name option" do
|
645
|
+
current_env_process_label = ENV['QS_PROCESS_LABEL']
|
646
|
+
|
647
|
+
ENV['QS_PROCESS_LABEL'] = Factory.string
|
648
|
+
config = Configuration.new(:name => Factory.string)
|
649
|
+
assert_equal ENV['QS_PROCESS_LABEL'], config.process_label
|
650
|
+
|
651
|
+
ENV['QS_PROCESS_LABEL'] = ''
|
652
|
+
config = Configuration.new(:name => Factory.string)
|
653
|
+
assert_equal config.name, config.process_label
|
654
|
+
|
655
|
+
ENV.delete('QS_PROCESS_LABEL')
|
656
|
+
config = Configuration.new(:name => Factory.string)
|
657
|
+
assert_equal config.name, config.process_label
|
658
|
+
|
659
|
+
ENV['QS_PROCESS_LABEL'] = current_env_process_label
|
660
|
+
end
|
661
|
+
|
577
662
|
should "not be valid by default" do
|
578
663
|
assert_false subject.valid?
|
579
664
|
end
|
@@ -582,12 +667,20 @@ module Qs::Daemon
|
|
582
667
|
assert_equal subject.queues.map(&:routes).flatten, subject.routes
|
583
668
|
end
|
584
669
|
|
585
|
-
should "include
|
670
|
+
should "include some attrs (not just the options) in its hash" do
|
586
671
|
config_hash = subject.to_hash
|
587
|
-
|
588
|
-
|
589
|
-
assert_equal
|
590
|
-
assert_equal subject.routes,
|
672
|
+
|
673
|
+
assert_equal subject.process_label, config_hash[:process_label]
|
674
|
+
assert_equal subject.error_procs, config_hash[:error_procs]
|
675
|
+
assert_equal subject.routes, config_hash[:routes]
|
676
|
+
|
677
|
+
exp = subject.queues.map(&:redis_key)
|
678
|
+
assert_equal exp, config_hash[:queue_redis_keys]
|
679
|
+
|
680
|
+
assert_equal subject.worker_start_procs, config_hash[:worker_start_procs]
|
681
|
+
assert_equal subject.worker_shutdown_procs, config_hash[:worker_shutdown_procs]
|
682
|
+
assert_equal subject.worker_sleep_procs, config_hash[:worker_sleep_procs]
|
683
|
+
assert_equal subject.worker_wakeup_procs, config_hash[:worker_wakeup_procs]
|
591
684
|
end
|
592
685
|
|
593
686
|
should "call its init procs when validated" do
|
data/test/unit/process_tests.rb
CHANGED
@@ -22,9 +22,7 @@ class Qs::Process
|
|
22
22
|
class InitTests < UnitTests
|
23
23
|
desc "when init"
|
24
24
|
setup do
|
25
|
-
@current_env_process_label = ENV['QS_PROCESS_LABEL']
|
26
25
|
@current_env_skip_daemonize = ENV['QS_SKIP_DAEMONIZE']
|
27
|
-
ENV.delete('QS_PROCESS_LABEL')
|
28
26
|
ENV.delete('QS_SKIP_DAEMONIZE')
|
29
27
|
|
30
28
|
@daemon_spy = DaemonSpy.new
|
@@ -41,7 +39,6 @@ class Qs::Process
|
|
41
39
|
end
|
42
40
|
teardown do
|
43
41
|
ENV['QS_SKIP_DAEMONIZE'] = @current_env_skip_daemonize
|
44
|
-
ENV['QS_PROCESS_LABEL'] = @current_env_process_label
|
45
42
|
end
|
46
43
|
subject{ @process }
|
47
44
|
|
@@ -54,24 +51,12 @@ class Qs::Process
|
|
54
51
|
end
|
55
52
|
|
56
53
|
should "know its name, pid file, signal io and restart cmd" do
|
57
|
-
assert_equal "qs: #{@daemon_spy.
|
54
|
+
assert_equal "qs: #{@daemon_spy.process_label}", subject.name
|
58
55
|
assert_equal @pid_file_spy, subject.pid_file
|
59
56
|
assert_instance_of Qs::IOPipe, subject.signal_io
|
60
57
|
assert_equal @restart_cmd_spy, subject.restart_cmd
|
61
58
|
end
|
62
59
|
|
63
|
-
should "set its name using env vars" do
|
64
|
-
ENV['QS_PROCESS_LABEL'] = Factory.string
|
65
|
-
process = @process_class.new(@daemon_spy)
|
66
|
-
assert_equal "qs: #{ENV['QS_PROCESS_LABEL']}", process.name
|
67
|
-
end
|
68
|
-
|
69
|
-
should "ignore blank env values for its name" do
|
70
|
-
ENV['QS_PROCESS_LABEL'] = ''
|
71
|
-
process = @process_class.new(@daemon_spy)
|
72
|
-
assert_equal "qs: #{@daemon_spy.name}", process.name
|
73
|
-
end
|
74
|
-
|
75
60
|
should "not daemonize by default" do
|
76
61
|
process = @process_class.new(@daemon_spy)
|
77
62
|
assert_false process.daemonize?
|
@@ -415,11 +400,15 @@ class Qs::Process
|
|
415
400
|
|
416
401
|
queue Qs::Queue.new{ name Factory.string }
|
417
402
|
|
403
|
+
attr_accessor :process_label
|
418
404
|
attr_accessor :start_called, :stop_called, :halt_called
|
419
405
|
attr_reader :start_args, :stop_args, :halt_args
|
420
406
|
|
421
407
|
def initialize(*args)
|
422
408
|
super
|
409
|
+
|
410
|
+
@process_label = Factory.string
|
411
|
+
|
423
412
|
@start_args = nil
|
424
413
|
@start_called = false
|
425
414
|
@stop_args = nil
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2015-08
|
19
|
+
date: 2015-09-08 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -84,11 +84,11 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
hash:
|
87
|
+
hash: 29
|
88
88
|
segments:
|
89
89
|
- 2
|
90
|
-
-
|
91
|
-
version: "2.
|
90
|
+
- 15
|
91
|
+
version: "2.15"
|
92
92
|
type: :development
|
93
93
|
name: assert
|
94
94
|
version_requirements: *id005
|
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
238
|
requirements: []
|
239
239
|
|
240
240
|
rubyforge_project:
|
241
|
-
rubygems_version: 1.8.
|
241
|
+
rubygems_version: 1.8.29
|
242
242
|
signing_key:
|
243
243
|
specification_version: 3
|
244
244
|
summary: Define message queues. Process jobs and events. Profit.
|