pebbles-river 0.1.6 → 0.1.7

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.
@@ -3,6 +3,8 @@ module Pebbles
3
3
 
4
4
  class ConfigurationError < StandardError; end
5
5
 
6
+ # A simple supervisor which runs workers in preforked pools of child processes.
7
+ # If a worker dies, a new child process is created.
6
8
  class Supervisor < Servolux::Server
7
9
 
8
10
  def initialize(name, options = {})
@@ -13,7 +15,6 @@ module Pebbles
13
15
  @worker_count = options[:worker_count] || 1
14
16
 
15
17
  @prefork_pools = []
16
-
17
18
  @worker_modules = []
18
19
  end
19
20
 
@@ -22,30 +23,41 @@ module Pebbles
22
23
  raise ConfigurationError.new("No listeners configured")
23
24
  end
24
25
 
25
- @worker_modules.each do |m|
26
+ @worker_modules.each do |min_worker_count, m|
26
27
  @prefork_pools.push(
27
28
  Servolux::Prefork.new(
28
- min_workers: @worker_count,
29
+ min_workers: min_worker_count,
29
30
  module: m))
30
31
  end
31
32
  end
32
33
 
34
+ # Add a listener. The listener must support the `#call(message)` method.
35
+ # The queue specification contains the parameters naming the queue and
36
+ # so on; see `Pebbles::River::River#queue`. The worker options:
37
+ #
38
+ # * `managed_acking`: Passed along to `Pebbles::River::Worker.new`.
39
+ # * `worker_count`: Number of parallel workers to run. Defaults to the
40
+ # global setting.
41
+ #
33
42
  def add_listener(listener, queue_spec, worker_options = {})
34
- worker = Pebbles::River::Worker.new(listener, {
43
+ worker_options.assert_valid_keys(:managed_acking, :worker_count)
44
+
45
+ worker = Pebbles::River::Worker.new(listener,
35
46
  queue: queue_spec,
47
+ managed_acking: worker_options[:managed_acking],
36
48
  on_exception: ->(e) {
37
49
  if logger.respond_to?(:exception)
38
50
  logger.exception(e)
39
51
  else
40
52
  logger.error("Exception #{e.class}: #{e} #{e.backtrace.join("\n")}")
41
53
  end
42
- }
43
- }.merge(worker_options))
54
+ })
44
55
 
45
56
  process_name = "#{@name}: queue worker: #{queue_spec[:name]}"
46
57
  logger = @logger
58
+ worker_count = worker_options[:worker_count] || @worker_count
47
59
 
48
- @worker_modules.push(Module.new {
60
+ @worker_modules.push([worker_count, Module.new {
49
61
  define_method :execute do
50
62
  $0 = process_name
51
63
  trap('TERM') do
@@ -55,7 +67,7 @@ module Pebbles
55
67
  end
56
68
  worker.run
57
69
  end
58
- })
70
+ }])
59
71
  end
60
72
 
61
73
  # From Servolux::Server
@@ -1,5 +1,5 @@
1
1
  module Pebbles
2
2
  module River
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebbles-river
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-10 00:00:00.000000000 Z
13
+ date: 2014-09-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pebblebed