multi_worker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +3 -1
- data/README.md +3 -1
- data/lib/multi_worker.rb +7 -6
- data/lib/multi_worker/adapters/delayed_job.rb +1 -1
- data/lib/multi_worker/adapters/sidekiq.rb +6 -6
- data/lib/multi_worker/adapters/sneakers.rb +1 -1
- data/lib/multi_worker/adapters/toro.rb +42 -0
- data/lib/multi_worker/tasks.rb +1 -1
- data/lib/multi_worker/version.rb +1 -1
- data/multi_worker.gemspec +7 -4
- data/spec/adapters/backburner_spec.rb +31 -31
- data/spec/adapters/delayed_job_spec.rb +31 -31
- data/spec/adapters/inline_spec.rb +17 -17
- data/spec/adapters/qu_spec.rb +28 -28
- data/spec/adapters/que_spec.rb +43 -43
- data/spec/adapters/queue_classic_spec.rb +40 -40
- data/spec/adapters/resque_spec.rb +73 -73
- data/spec/adapters/sidekiq_spec.rb +90 -90
- data/spec/adapters/sneakers_spec.rb +35 -35
- data/spec/adapters/sucker_punch_spec.rb +2 -2
- data/spec/adapters/threaded_in_memory_queue_spec.rb +24 -24
- data/spec/adapters/toro_spec.rb +64 -0
- data/spec/adapters/torquebox_backgroundable_spec.rb +30 -30
- data/spec/configuration_spec.rb +60 -58
- data/spec/shared/worker_spec.rb +17 -17
- data/spec/spec_helper.rb +1 -1
- data/spec/test_workers.rb +6 -6
- metadata +69 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58371d2a8351fc6f496e304c4e6c7907df5c9e92
|
4
|
+
data.tar.gz: fde9e1540640108d612c985814eb18e135b4646a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faa930571ed54febc0e974799ce547525718c0e81380052576fe0f62cd4340995642b648b806b902c2f4e5d597fd8869ba7b0a3e212d42f8d8ee443b815f7219
|
7
|
+
data.tar.gz: d7b6d3bd0fba6d269aa09e761ea678968006985659203684b73961c20b23e12dadd6ad1a80ba28ea2a08a1708bfa1e599d964d93210d6d953fadffbb444b46a7
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# MultiWorker
|
1
|
+
# MultiWorker
|
2
|
+
[![Build Status](https://travis-ci.org/dwbutler/multi_worker.png?branch=master)](https://travis-ci.org/dwbutler/multi_worker) [![Code Climate](https://codeclimate.com/github/dwbutler/multi_worker.png)](https://codeclimate.com/github/dwbutler/multi_worker) [![Dependency Status](https://gemnasium.com/dwbutler/multi_worker.svg)](https://gemnasium.com/dwbutler/multi_worker)
|
2
3
|
|
3
4
|
MultiWorker provides a common interface to the (many) Ruby queueing/worker libraries.
|
4
5
|
They are all very similar, but provide slightly different interfaces. This makes it difficult
|
@@ -94,6 +95,7 @@ end
|
|
94
95
|
| Qu | Redis, Mongo, SQS | | | | | | | | ✓ | ✓ |
|
95
96
|
| Queue Classic | PostgreSQL | | | | | | | | ✓ | ✗ |
|
96
97
|
| Que | PostgreSQL | | | | | ✓ | ✓ | | ✓ | ✓ |
|
98
|
+
| Toro | PostgreSQL | ✓ | ✓ | | | ✓ | | | ✓ | ✗ |
|
97
99
|
| Sneakers | RabbitMQ | | | | | | | | ✗ | ✗ |
|
98
100
|
| TorqueBox Backgroundable | HornetQ | ✓ | | | | | | ✓ | ✗ | ✗ |
|
99
101
|
| Backburner | Beanstalkd | | ✓ | | | ✓ | ✓ | ✓ | ✓ | ✓ |
|
data/lib/multi_worker.rb
CHANGED
@@ -31,12 +31,12 @@ module MultiWorker
|
|
31
31
|
|
32
32
|
def default_options(opts={})
|
33
33
|
@default_options ||= {
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
34
|
+
adapter: default_adapter,
|
35
|
+
queue: default_queue,
|
36
|
+
status: false,
|
37
|
+
retry: false,
|
38
|
+
lock: false,
|
39
|
+
unique: false
|
40
40
|
}
|
41
41
|
|
42
42
|
if opts && !opts.empty?
|
@@ -63,6 +63,7 @@ module MultiWorker
|
|
63
63
|
when defined?(::ThreadedInMemoryQueue) then :threaded_in_memory_queue
|
64
64
|
when defined?(::SuckerPunch::Job) then :sucker_punch
|
65
65
|
when defined?(::Backburner) then :backburner
|
66
|
+
when defined?(::Toro) then :toro
|
66
67
|
else :inline
|
67
68
|
end
|
68
69
|
end
|
@@ -11,20 +11,20 @@ module MultiWorker
|
|
11
11
|
end
|
12
12
|
|
13
13
|
@sidekiq_options = ::Sidekiq.default_worker_options.symbolize_keys
|
14
|
-
@sidekiq_options.merge! :
|
14
|
+
@sidekiq_options.merge! queue: opts[:queue]
|
15
15
|
|
16
16
|
if opts.has_key?(:backtrace)
|
17
|
-
@sidekiq_options.merge! :
|
17
|
+
@sidekiq_options.merge! backtrace: opts[:backtrace]
|
18
18
|
end
|
19
19
|
|
20
20
|
if opts.has_key?(:retry)
|
21
21
|
@retry = opts[:retry]
|
22
22
|
case @retry
|
23
23
|
when Hash
|
24
|
-
@sidekiq_options.merge!(:
|
24
|
+
@sidekiq_options.merge!(retry: @retry[:limit])
|
25
25
|
sidekiq_retry_in(&@retry[:delay])
|
26
26
|
when true, false, Fixnum
|
27
|
-
@sidekiq_options.merge!(:
|
27
|
+
@sidekiq_options.merge!(retry: @retry)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,12 +32,12 @@ module MultiWorker
|
|
32
32
|
require 'sidekiq-lock'
|
33
33
|
include ::Sidekiq::Lock::Worker
|
34
34
|
|
35
|
-
@sidekiq_options.merge!(:
|
35
|
+
@sidekiq_options.merge!(lock: opts[:lock])
|
36
36
|
end
|
37
37
|
|
38
38
|
if opts[:unique]
|
39
39
|
require "sidekiq-unique-jobs"
|
40
|
-
@sidekiq_options.merge!(:
|
40
|
+
@sidekiq_options.merge!(unique: true)
|
41
41
|
end
|
42
42
|
|
43
43
|
sidekiq_options @sidekiq_options
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MultiWorker
|
2
|
+
module Adapters
|
3
|
+
class Toro
|
4
|
+
def self.configure(base, opts={})
|
5
|
+
base.class_eval do
|
6
|
+
include ::Toro::Worker
|
7
|
+
|
8
|
+
@queue = opts[:queue]
|
9
|
+
@toro_options = {queue: @queue}
|
10
|
+
|
11
|
+
if opts.has_key?(:retry)
|
12
|
+
@retry = opts[:retry]
|
13
|
+
case @retry
|
14
|
+
when Hash
|
15
|
+
@toro_options.merge!(retry_interval: @retry[:delay])
|
16
|
+
when Fixnum, ActiveSupport::Duration
|
17
|
+
@toro_options.merge!(retry_interval: @retry)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
toro_options @toro_options
|
22
|
+
|
23
|
+
def self.perform(*args)
|
24
|
+
self.new.perform(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform_async(*args)
|
28
|
+
self.class.perform_async(*args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.rake_task
|
34
|
+
require 'rake'
|
35
|
+
require 'toro'
|
36
|
+
require 'tasks/tasks'
|
37
|
+
::Rake::Task["toro"]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/lib/multi_worker/tasks.rb
CHANGED
@@ -6,7 +6,7 @@ task :environment
|
|
6
6
|
|
7
7
|
namespace :multi_worker do
|
8
8
|
desc "Start a new worker for #{MultiWorker.default_adapter}"
|
9
|
-
task :
|
9
|
+
task work: :environment do
|
10
10
|
rake_task = MultiWorker.adapter.rake_task rescue fail("No rake task available for #{MultiWorker.default_adapter}")
|
11
11
|
rake_task.execute
|
12
12
|
end
|
data/lib/multi_worker/version.rb
CHANGED
data/multi_worker.gemspec
CHANGED
@@ -40,8 +40,13 @@ Gem::Specification.new do |spec|
|
|
40
40
|
|
41
41
|
spec.add_development_dependency "qu", "0.2.0"
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
if RUBY_ENGINE == "jruby"
|
44
|
+
spec.add_development_dependency "torquebox-messaging"
|
45
|
+
else
|
46
|
+
spec.add_development_dependency "queue_classic"
|
47
|
+
spec.add_development_dependency "toro"
|
48
|
+
end
|
49
|
+
|
45
50
|
spec.add_development_dependency "que"
|
46
51
|
|
47
52
|
spec.add_development_dependency "sneakers"
|
@@ -51,6 +56,4 @@ Gem::Specification.new do |spec|
|
|
51
56
|
spec.add_development_dependency "sucker_punch"
|
52
57
|
|
53
58
|
spec.add_development_dependency "backburner"
|
54
|
-
|
55
|
-
spec.add_development_dependency "torquebox-messaging" if (RUBY_ENGINE == "jruby")
|
56
59
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'backburner'
|
2
|
-
require 'test_workers'
|
3
|
-
|
4
|
-
describe TestWorker do
|
5
|
-
it_behaves_like "a worker"
|
6
|
-
|
7
|
-
it { should be_a ::Backburner::Queue }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe MultiWorker do
|
11
|
-
context "when Backburner is loaded" do
|
12
|
-
it "defaults to the :backburner adapter" do
|
13
|
-
MultiWorker.default_adapter.
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when using the :backburner adapter" do
|
18
|
-
it "::perform_async uses Backburner" do
|
19
|
-
Backburner.
|
20
|
-
TestWorker.perform_async("foo")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "MultiWorker.enqueue uses Backburner" do
|
24
|
-
Backburner.
|
25
|
-
MultiWorker.enqueue(TestWorker, "foo")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "exposes the Backburner rake task" do
|
29
|
-
MultiWorker.adapter.rake_task.name.
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'backburner'
|
2
|
+
require 'test_workers'
|
3
|
+
|
4
|
+
describe TestWorker do
|
5
|
+
it_behaves_like "a worker"
|
6
|
+
|
7
|
+
it { should be_a ::Backburner::Queue }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe MultiWorker do
|
11
|
+
context "when Backburner is loaded" do
|
12
|
+
it "defaults to the :backburner adapter" do
|
13
|
+
expect(MultiWorker.default_adapter).to eq(:backburner)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when using the :backburner adapter" do
|
18
|
+
it "::perform_async uses Backburner" do
|
19
|
+
expect(Backburner).to receive(:enqueue).once.with(TestWorker, "foo")
|
20
|
+
TestWorker.perform_async("foo")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "MultiWorker.enqueue uses Backburner" do
|
24
|
+
expect(Backburner).to receive(:enqueue).once.with(TestWorker, "foo")
|
25
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "exposes the Backburner rake task" do
|
29
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("backburner:work")
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'delayed_job'
|
2
|
-
require 'delayed/backend/test'
|
3
|
-
Delayed::Worker.backend = :test
|
4
|
-
#require 'delayed_job_active_record'
|
5
|
-
Delayed::Worker.delay_jobs = false
|
6
|
-
|
7
|
-
require 'test_workers'
|
8
|
-
|
9
|
-
describe TestWorker do
|
10
|
-
it_behaves_like "a worker"
|
11
|
-
end
|
12
|
-
|
13
|
-
describe MultiWorker do
|
14
|
-
context "when Delayed::Job is loaded" do
|
15
|
-
it "defaults to the :delayed_job adapter" do
|
16
|
-
MultiWorker.default_adapter.
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when using the :delayed_job adapter" do
|
21
|
-
it "performs the work using Delayed::Job" do
|
22
|
-
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
23
|
-
TestWorker.perform_async("foo")
|
24
|
-
MultiWorker.enqueue(TestWorker, "foo")
|
25
|
-
TestWorker.perform("foo")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "exposes the Delayed Job rake task" do
|
29
|
-
MultiWorker.adapter.rake_task.name.
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'delayed_job'
|
2
|
+
require 'delayed/backend/test'
|
3
|
+
Delayed::Worker.backend = :test
|
4
|
+
#require 'delayed_job_active_record'
|
5
|
+
Delayed::Worker.delay_jobs = false
|
6
|
+
|
7
|
+
require 'test_workers'
|
8
|
+
|
9
|
+
describe TestWorker do
|
10
|
+
it_behaves_like "a worker"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe MultiWorker do
|
14
|
+
context "when Delayed::Job is loaded" do
|
15
|
+
it "defaults to the :delayed_job adapter" do
|
16
|
+
expect(MultiWorker.default_adapter).to eq(:delayed_job)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when using the :delayed_job adapter" do
|
21
|
+
it "performs the work using Delayed::Job" do
|
22
|
+
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
23
|
+
TestWorker.perform_async("foo")
|
24
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
25
|
+
TestWorker.perform("foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "exposes the Delayed Job rake task" do
|
29
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("jobs:work")
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'test_workers'
|
2
|
-
|
3
|
-
describe MultiWorker do
|
4
|
-
context "when no other adapter is available" do
|
5
|
-
it "defaults to the :inline adapter" do
|
6
|
-
MultiWorker.default_adapter.
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context "when using the :inline adapter" do
|
11
|
-
it "performs the work immediately" do
|
12
|
-
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
13
|
-
TestWorker.perform_async("foo")
|
14
|
-
MultiWorker.enqueue(TestWorker, "foo")
|
15
|
-
TestWorker.perform("foo")
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require 'test_workers'
|
2
|
+
|
3
|
+
describe MultiWorker do
|
4
|
+
context "when no other adapter is available" do
|
5
|
+
it "defaults to the :inline adapter" do
|
6
|
+
expect(MultiWorker.default_adapter).to eq(:inline)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when using the :inline adapter" do
|
11
|
+
it "performs the work immediately" do
|
12
|
+
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
13
|
+
TestWorker.perform_async("foo")
|
14
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
15
|
+
TestWorker.perform("foo")
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
data/spec/adapters/qu_spec.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'qu'
|
2
|
-
require 'qu-immediate'
|
3
|
-
|
4
|
-
require 'test_workers'
|
5
|
-
|
6
|
-
describe TestWorker do
|
7
|
-
it_behaves_like "a worker"
|
8
|
-
end
|
9
|
-
|
10
|
-
describe MultiWorker do
|
11
|
-
context "when Qu is loaded" do
|
12
|
-
it "defaults to the :qu adapter" do
|
13
|
-
MultiWorker.default_adapter.
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when using the :qu adapter" do
|
18
|
-
it "performs the work using Qu's backend" do
|
19
|
-
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
20
|
-
TestWorker.perform_async("foo")
|
21
|
-
MultiWorker.enqueue(TestWorker, "foo")
|
22
|
-
TestWorker.perform("foo")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "exposes the Qu rake task" do
|
26
|
-
MultiWorker.adapter.rake_task.name.
|
27
|
-
end
|
28
|
-
end
|
1
|
+
require 'qu'
|
2
|
+
require 'qu-immediate'
|
3
|
+
|
4
|
+
require 'test_workers'
|
5
|
+
|
6
|
+
describe TestWorker do
|
7
|
+
it_behaves_like "a worker"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe MultiWorker do
|
11
|
+
context "when Qu is loaded" do
|
12
|
+
it "defaults to the :qu adapter" do
|
13
|
+
expect(MultiWorker.default_adapter).to eq(:qu)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when using the :qu adapter" do
|
18
|
+
it "performs the work using Qu's backend" do
|
19
|
+
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
20
|
+
TestWorker.perform_async("foo")
|
21
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
22
|
+
TestWorker.perform("foo")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "exposes the Qu rake task" do
|
26
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("qu:work")
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|
data/spec/adapters/que_spec.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'que'
|
2
|
-
require 'active_record'
|
3
|
-
::Que.mode = :sync
|
4
|
-
|
5
|
-
require 'test_workers'
|
6
|
-
|
7
|
-
describe TestWorker do
|
8
|
-
it_behaves_like "a worker"
|
9
|
-
|
10
|
-
it { TestWorker::Job.
|
11
|
-
end
|
12
|
-
|
13
|
-
describe MultiWorker do
|
14
|
-
context "when Que is loaded" do
|
15
|
-
it "defaults to the :que adapter" do
|
16
|
-
MultiWorker.default_adapter.
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when using the :que adapter" do
|
21
|
-
before(:each) do
|
22
|
-
Que::Job.any_instance.stub(:
|
23
|
-
end
|
24
|
-
|
25
|
-
it "forwards ::perform to #perform" do
|
26
|
-
expect_any_instance_of(TestWorker).to receive(:perform).once.with("foo")
|
27
|
-
TestWorker.perform("foo")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "::perform_async performs the work using Que" do
|
31
|
-
expect_any_instance_of(TestWorker).to receive(:perform).once
|
32
|
-
TestWorker.perform_async("foo")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "MultiWorker.enqueue performs the work using Que" do
|
36
|
-
expect_any_instance_of(TestWorker).to receive(:perform).once
|
37
|
-
MultiWorker.enqueue(TestWorker, "foo")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "exposes the Que rake task" do
|
41
|
-
MultiWorker.adapter.rake_task.name.
|
42
|
-
end
|
43
|
-
end
|
1
|
+
require 'que'
|
2
|
+
require 'active_record'
|
3
|
+
::Que.mode = :sync
|
4
|
+
|
5
|
+
require 'test_workers'
|
6
|
+
|
7
|
+
describe TestWorker do
|
8
|
+
it_behaves_like "a worker"
|
9
|
+
|
10
|
+
it { expect(TestWorker::Job).to be < ::Que::Job }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe MultiWorker do
|
14
|
+
context "when Que is loaded" do
|
15
|
+
it "defaults to the :que adapter" do
|
16
|
+
expect(MultiWorker.default_adapter).to eq(:que)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when using the :que adapter" do
|
21
|
+
before(:each) do
|
22
|
+
Que::Job.any_instance.stub(destroy: true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "forwards ::perform to #perform" do
|
26
|
+
expect_any_instance_of(TestWorker).to receive(:perform).once.with("foo")
|
27
|
+
TestWorker.perform("foo")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "::perform_async performs the work using Que" do
|
31
|
+
expect_any_instance_of(TestWorker).to receive(:perform).once
|
32
|
+
TestWorker.perform_async("foo")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "MultiWorker.enqueue performs the work using Que" do
|
36
|
+
expect_any_instance_of(TestWorker).to receive(:perform).once
|
37
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "exposes the Que rake task" do
|
41
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("que:work")
|
42
|
+
end
|
43
|
+
end
|
44
44
|
end
|