resqued 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fae73470c551f27a4848c17b82495aa3796d604c
4
- data.tar.gz: 195b59de0a56db9d9f4a8cedc7021b89e08bb38d
3
+ metadata.gz: ea3c0cf8313a982fc5c760f5ae8f7d6b7ed011d1
4
+ data.tar.gz: d9f06f7f2149de4cf608dc696a4e4bcf5cc77719
5
5
  SHA512:
6
- metadata.gz: fda785e004ce32e7cfae246c8189d60ec26124594a6f5032698e30d633e266af3112cc24430249cb508552348b8ee15cf7fd470b45b842ae04de9a005d82df6b
7
- data.tar.gz: fbd9e34d38907b72014ffaf3c0b58f8305ed803445dc48de245a1027de74c3cd002f0c90dc7c333d8d7c0d3812084f02b6146a273b0c3981d058079db64879fa
6
+ metadata.gz: 63277a13dd24c301ab7d389600bccd710cf67b4357ebeb33c14e673fdb076e265171a1a938a747f8a7d79007c8eb5e2376092af17f504c9c78ea3a3bca08e2d6
7
+ data.tar.gz: 7a41b8ef12b7962434887cc2498e4c69d2699bf186c160237fb829bf901efb4b969962c2a79455ce4cfb21deff71d923247e9fb0163bde07ac426e56f98e9617
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Starting with version 0.6.1, resqued uses semantic versioning to indicate incompatibilities between the master process, listener process, and configuration.
2
2
 
3
+ v0.8.5
4
+ ------
5
+ * Accept a custom proc to create the worker object.
6
+
3
7
  v0.8.4
4
8
  ------
5
9
  * Use `Integer` in place of `Fixnum`, when it's available.
@@ -20,6 +20,10 @@ module Resqued
20
20
  def worker_pool(count, *queues_and_options)
21
21
  end
22
22
 
23
+ # Public: Define a factory Proc that creates Resque::Workers
24
+ def worker_factory(&block)
25
+ end
26
+
23
27
  # Public: Define the queues worked by members of the worker pool.
24
28
  def queue(*queues)
25
29
  end
@@ -36,6 +36,14 @@ module Resqued
36
36
  queues.each { |q| queue q }
37
37
  end
38
38
 
39
+ # DSL: Define a factory Proc used to create Resque::Workers. The factory
40
+ # Proc receives a list of queues as an argument.
41
+ #
42
+ # worker_factory { |queues| Resque::Worker.new(*queues) }
43
+ def worker_factory(&block)
44
+ @worker_options.merge!(worker_factory: block)
45
+ end
46
+
39
47
  # DSL: Define a queue for the worker_pool to work from.
40
48
  #
41
49
  # queue 'one'
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = '0.8.4'
2
+ VERSION = '0.8.5'
3
3
  end
@@ -8,11 +8,19 @@ module Resqued
8
8
  class Worker
9
9
  include Resqued::Logging
10
10
 
11
+ DEFAULT_WORKER_FACTORY = ->(queues) {
12
+ resque_worker = Resque::Worker.new(*queues)
13
+ resque_worker.term_child = true if resque_worker.respond_to?('term_child=')
14
+ Resque.redis.client.reconnect
15
+ resque_worker
16
+ }
17
+
11
18
  def initialize(options)
12
19
  @queues = options.fetch(:queues)
13
20
  @config = options.fetch(:config)
14
21
  @interval = options[:interval]
15
22
  @backoff = Backoff.new
23
+ @worker_factory = options.fetch(:worker_factory, DEFAULT_WORKER_FACTORY)
16
24
  @pids = []
17
25
  end
18
26
 
@@ -80,9 +88,7 @@ module Resqued
80
88
  Resqued::Listener::ALL_SIGNALS.each { |signal| trap(signal, 'DEFAULT') }
81
89
  trap(:QUIT) { exit! 0 } # If we get a QUIT during boot, just spin back down.
82
90
  $0 = "STARTING RESQUE FOR #{queues.join(',')}"
83
- resque_worker = Resque::Worker.new(*queues)
84
- resque_worker.term_child = true if resque_worker.respond_to?('term_child=')
85
- Resque.redis.client.reconnect
91
+ resque_worker = @worker_factory.call(queues)
86
92
  @config.after_fork(resque_worker)
87
93
  resque_worker.work(@interval || 5)
88
94
  exit 0
@@ -140,6 +140,29 @@ describe Resqued::Config::Worker do
140
140
  it { expect(result[3]).to eq(:queues => ['*']) }
141
141
  end
142
142
 
143
+ context 'worker factory' do
144
+ let(:config) { <<-END_CONFIG }
145
+ worker_factory { |queues| queues }
146
+ worker 'a'
147
+ END_CONFIG
148
+
149
+ it { expect(result.size).to eq(1) }
150
+ it { expect(result[0].reject { |k, _| k == :worker_factory}).to eq(:queues => ['a']) }
151
+ it { expect(result[0][:worker_factory].call(result[0][:queues])).to eq(['a']) }
152
+ end
153
+
154
+ context 'worker factory with pool' do
155
+ let(:config) { <<-END_CONFIG }
156
+ worker_factory { |queues| queues }
157
+ worker_pool 1
158
+ queue 'a'
159
+ END_CONFIG
160
+
161
+ it { expect(result.size).to eq(1) }
162
+ it { expect(result[0].reject { |k, _| k == :worker_factory}).to eq(:queues => ['a']) }
163
+ it { expect(result[0][:worker_factory].call(result[0][:queues])).to eq(['a']) }
164
+ end
165
+
143
166
  context 'with default options' do
144
167
  let(:evaluator) { described_class.new(:worker_class => FakeWorker, :config => 'something') }
145
168
  let(:config) { <<-END_CONFIG }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resqued
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Burke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio
@@ -156,22 +156,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  requirements: []
158
158
  rubyforge_project:
159
- rubygems_version: 2.2.2
159
+ rubygems_version: 2.5.2.3
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Daemon of resque workers
163
163
  test_files:
164
- - spec/resqued/sleepy_spec.rb
165
- - spec/resqued/backoff_spec.rb
166
- - spec/resqued/config/worker_spec.rb
167
- - spec/resqued/config/fork_event_spec.rb
168
- - spec/resqued/start_ctx_spec.rb
169
- - spec/resqued/config_spec.rb
170
- - spec/resqued/test_case_spec.rb
171
164
  - spec/spec_helper.rb
165
+ - spec/support/custom_matchers.rb
166
+ - spec/fixtures/test_case_clean.rb
172
167
  - spec/fixtures/test_case_before_fork_raises.rb
173
168
  - spec/fixtures/test_case_environment.rb
174
169
  - spec/fixtures/test_case_no_workers.rb
175
170
  - spec/fixtures/test_case_after_fork_raises.rb
176
- - spec/fixtures/test_case_clean.rb
177
- - spec/support/custom_matchers.rb
171
+ - spec/resqued/config_spec.rb
172
+ - spec/resqued/config/fork_event_spec.rb
173
+ - spec/resqued/config/worker_spec.rb
174
+ - spec/resqued/sleepy_spec.rb
175
+ - spec/resqued/test_case_spec.rb
176
+ - spec/resqued/start_ctx_spec.rb
177
+ - spec/resqued/backoff_spec.rb