multi_worker 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +110 -0
- data/Rakefile +22 -0
- data/lib/multi_worker/adapters/backburner.rb +32 -0
- data/lib/multi_worker/adapters/delayed_job.rb +30 -0
- data/lib/multi_worker/adapters/inline.rb +21 -0
- data/lib/multi_worker/adapters/qu.rb +30 -0
- data/lib/multi_worker/adapters/que.rb +47 -0
- data/lib/multi_worker/adapters/queue_classic.rb +29 -0
- data/lib/multi_worker/adapters/resque.rb +59 -0
- data/lib/multi_worker/adapters/sidekiq.rb +56 -0
- data/lib/multi_worker/adapters/sneakers.rb +32 -0
- data/lib/multi_worker/adapters/sucker_punch.rb +25 -0
- data/lib/multi_worker/adapters/threaded_in_memory_queue.rb +27 -0
- data/lib/multi_worker/adapters/torquebox_backgroundable.rb +25 -0
- data/lib/multi_worker/interface.rb +24 -0
- data/lib/multi_worker/tasks.rb +13 -0
- data/lib/multi_worker/version.rb +3 -0
- data/lib/multi_worker.rb +79 -0
- data/multi_worker.gemspec +56 -0
- data/spec/adapters/backburner_spec.rb +32 -0
- data/spec/adapters/delayed_job_spec.rb +32 -0
- data/spec/adapters/inline_spec.rb +18 -0
- data/spec/adapters/qu_spec.rb +29 -0
- data/spec/adapters/que_spec.rb +44 -0
- data/spec/adapters/queue_classic_spec.rb +41 -0
- data/spec/adapters/resque_spec.rb +74 -0
- data/spec/adapters/sidekiq_spec.rb +91 -0
- data/spec/adapters/sneakers_spec.rb +36 -0
- data/spec/adapters/sucker_punch_spec.rb +36 -0
- data/spec/adapters/threaded_in_memory_queue_spec.rb +25 -0
- data/spec/adapters/torquebox_backgroundable_spec.rb +31 -0
- data/spec/configuration_spec.rb +59 -0
- data/spec/delayed/backend/test.rb +113 -0
- data/spec/delayed/serialization/test.rb +0 -0
- data/spec/shared/worker_spec.rb +18 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/test_workers.rb +7 -0
- metadata +427 -0
data/lib/multi_worker.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "multi_worker/version"
|
2
|
+
require "multi_worker/interface"
|
3
|
+
|
4
|
+
module MultiWorker
|
5
|
+
@adapters = {}
|
6
|
+
@default_queue = :default
|
7
|
+
|
8
|
+
AdapterNames = [
|
9
|
+
:resque,
|
10
|
+
:sidekiq,
|
11
|
+
:delayed_job,
|
12
|
+
:qu,
|
13
|
+
:queue_classic,
|
14
|
+
:que,
|
15
|
+
:sneakers,
|
16
|
+
:torquebox_backgroundable,
|
17
|
+
:threaded_in_memory_queue,
|
18
|
+
:sucker_punch,
|
19
|
+
:backburner,
|
20
|
+
:inline
|
21
|
+
]
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def enqueue(worker_klass, *args)
|
25
|
+
worker_klass.perform_async(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure(&block)
|
29
|
+
instance_eval &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_options(opts={})
|
33
|
+
@default_options ||= {
|
34
|
+
:adapter => default_adapter,
|
35
|
+
:queue => default_queue,
|
36
|
+
:status => false,
|
37
|
+
:retry => false,
|
38
|
+
:lock => false,
|
39
|
+
:unique => false
|
40
|
+
}
|
41
|
+
|
42
|
+
if opts && !opts.empty?
|
43
|
+
@default_options.merge!(opts)
|
44
|
+
end
|
45
|
+
|
46
|
+
@default_options
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_accessor :default_queue
|
50
|
+
|
51
|
+
def default_adapter(adapter_name=nil)
|
52
|
+
return (@default_adapter = adapter_name) if (adapter_name && !adapter_name.empty?)
|
53
|
+
|
54
|
+
@default_adapter ||= case
|
55
|
+
when defined?(::Resque) then :resque
|
56
|
+
when defined?(::Sidekiq) then :sidekiq
|
57
|
+
when defined?(::Delayed::Worker) then :delayed_job
|
58
|
+
when defined?(::Qu) then :qu
|
59
|
+
when defined?(::QC::Queue) then :queue_classic
|
60
|
+
when defined?(::Que) then :que
|
61
|
+
when defined?(::Sneakers::Worker) then :sneakers
|
62
|
+
when defined?(::TorqueBox::Messaging::Backgroundable) then :torquebox_backgroundable
|
63
|
+
when defined?(::ThreadedInMemoryQueue) then :threaded_in_memory_queue
|
64
|
+
when defined?(::SuckerPunch::Job) then :sucker_punch
|
65
|
+
when defined?(::Backburner) then :backburner
|
66
|
+
else :inline
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def adapter(adapter_name=nil)
|
71
|
+
adapter_name ||= default_adapter
|
72
|
+
@adapters[adapter_name] ||= begin
|
73
|
+
require "multi_worker/adapters/#{adapter_name}"
|
74
|
+
klass_name = adapter_name.to_s.split('_').map(&:capitalize) * ''
|
75
|
+
MultiWorker::Adapters.const_get(klass_name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multi_worker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "multi_worker"
|
8
|
+
spec.version = MultiWorker::VERSION
|
9
|
+
spec.authors = ["David Butler"]
|
10
|
+
spec.email = ["dwbutler@ucla.edu"]
|
11
|
+
spec.summary = %q{Provides a common interface to Ruby worker/queue libraries.}
|
12
|
+
spec.description = %q{Provides a common interface to Ruby worker/queue libraries.}
|
13
|
+
spec.homepage = "https://github.com/dwbutler/multi_worker"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_development_dependency "resque"
|
26
|
+
spec.add_development_dependency "resque-retry"
|
27
|
+
spec.add_development_dependency "resque-status"
|
28
|
+
spec.add_development_dependency "resque-loner"
|
29
|
+
spec.add_development_dependency "resque-lock-timeout"
|
30
|
+
spec.add_development_dependency "resque-delay"
|
31
|
+
|
32
|
+
spec.add_development_dependency "sidekiq"
|
33
|
+
spec.add_development_dependency "sidekiq-lock"
|
34
|
+
spec.add_development_dependency "sidekiq_status"
|
35
|
+
spec.add_development_dependency "sidekiq-unique-jobs"
|
36
|
+
spec.add_development_dependency "sidekiq-delay"
|
37
|
+
|
38
|
+
spec.add_development_dependency "delayed_job"
|
39
|
+
spec.add_development_dependency "delayed_job_active_record"
|
40
|
+
|
41
|
+
spec.add_development_dependency "qu", "0.2.0"
|
42
|
+
|
43
|
+
spec.add_development_dependency "queue_classic" unless (RUBY_ENGINE == "jruby")
|
44
|
+
|
45
|
+
spec.add_development_dependency "que"
|
46
|
+
|
47
|
+
spec.add_development_dependency "sneakers"
|
48
|
+
|
49
|
+
spec.add_development_dependency "threaded_in_memory_queue"
|
50
|
+
|
51
|
+
spec.add_development_dependency "sucker_punch"
|
52
|
+
|
53
|
+
spec.add_development_dependency "backburner"
|
54
|
+
|
55
|
+
spec.add_development_dependency "torquebox-messaging" if (RUBY_ENGINE == "jruby")
|
56
|
+
end
|
@@ -0,0 +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.should == :backburner
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when using the :backburner adapter" do
|
18
|
+
it "::perform_async uses Backburner" do
|
19
|
+
Backburner.should_receive(:enqueue).once.with(TestWorker, "foo")
|
20
|
+
TestWorker.perform_async("foo")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "MultiWorker.enqueue uses Backburner" do
|
24
|
+
Backburner.should_receive(:enqueue).once.with(TestWorker, "foo")
|
25
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "exposes the Backburner rake task" do
|
29
|
+
MultiWorker.adapter.rake_task.name.should == "backburner:work"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +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.should == :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
|
+
MultiWorker.adapter.rake_task.name.should == "jobs:work"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +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.should == :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
|
+
end
|
@@ -0,0 +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.should == :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
|
+
MultiWorker.adapter.rake_task.name.should == "qu:work"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +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.should 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
|
+
MultiWorker.default_adapter.should == :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
|
+
MultiWorker.adapter.rake_task.name.should == "que:work"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
exit if jruby?
|
2
|
+
|
3
|
+
ENV["DATABASE_URL"] ||= "postgres:///queue_classic_test"
|
4
|
+
require 'queue_classic'
|
5
|
+
|
6
|
+
module QC
|
7
|
+
class Queue
|
8
|
+
def enqueue(method, *args)
|
9
|
+
klass = eval(method.split(".").first)
|
10
|
+
message = method.split(".").last
|
11
|
+
klass.send(message, *args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'test_workers'
|
17
|
+
|
18
|
+
describe TestWorker do
|
19
|
+
it_behaves_like "a worker"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe MultiWorker do
|
23
|
+
context "when Queue Classic is loaded" do
|
24
|
+
it "defaults to the :queue_classic adapter" do
|
25
|
+
MultiWorker.default_adapter.should == :queue_classic
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when using the :queue_classic adapter" do
|
30
|
+
it "performs the work using Queue Classic" do
|
31
|
+
expect(TestWorker).to receive(:perform).exactly(3).times.with("foo")
|
32
|
+
TestWorker.perform_async("foo")
|
33
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
34
|
+
TestWorker.perform("foo")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "exposes the Queue Classic rake task" do
|
38
|
+
MultiWorker.adapter.rake_task.name.should == "qc:work"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'resque'
|
2
|
+
Resque.inline = true
|
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 Resque is loaded" do
|
12
|
+
it "defaults to the :resque adapter" do
|
13
|
+
MultiWorker.default_adapter.should == :resque
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when using the :resque adapter" do
|
18
|
+
it "performs the work using Resque" 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
|
+
context "with advanced options" do
|
26
|
+
it "configures :retry option" do
|
27
|
+
retry_worker = Class.new do
|
28
|
+
worker :retry => {:limit => 10, :delay => 5 }
|
29
|
+
end
|
30
|
+
|
31
|
+
retry_worker.should be_a ::Resque::Plugins::Retry
|
32
|
+
retry_worker.instance_variable_get(:@retry_limit).should == 10
|
33
|
+
retry_worker.instance_variable_get(:@retry_delay).should == 5
|
34
|
+
end
|
35
|
+
|
36
|
+
it "configures :lock option" do
|
37
|
+
locking_worker = Class.new do
|
38
|
+
worker :lock => {:timeout => 5}
|
39
|
+
end
|
40
|
+
|
41
|
+
locking_worker.should be_a ::Resque::Plugins::LockTimeout
|
42
|
+
locking_worker.instance_variable_get(:@lock_timeout).should == 5
|
43
|
+
end
|
44
|
+
|
45
|
+
it "configures :unique option with :lock" do
|
46
|
+
unique_worker = Class.new do
|
47
|
+
worker :lock => true, :unique => true
|
48
|
+
end
|
49
|
+
|
50
|
+
unique_worker.instance_variable_get(:@loner).should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "configures :unique option without :lock" do
|
54
|
+
unique_worker = Class.new do
|
55
|
+
worker :unique => true
|
56
|
+
end
|
57
|
+
|
58
|
+
unique_worker.should include ::Resque::Plugins::UniqueJob
|
59
|
+
end
|
60
|
+
|
61
|
+
it "configures :status option" do
|
62
|
+
status_worker = Class.new do
|
63
|
+
worker :status => true
|
64
|
+
end
|
65
|
+
|
66
|
+
status_worker.should include ::Resque::Plugins::Status
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "exposes the Resque rake task" do
|
71
|
+
MultiWorker.adapter.rake_task.name.should == "resque:work"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
require 'sidekiq/testing'
|
3
|
+
::Sidekiq::Testing.fake!
|
4
|
+
|
5
|
+
require 'test_workers'
|
6
|
+
|
7
|
+
describe TestWorker do
|
8
|
+
it_behaves_like "a worker"
|
9
|
+
|
10
|
+
it { should be_a ::Sidekiq::Worker }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe MultiWorker do
|
14
|
+
context "when Sidekiq is loaded" do
|
15
|
+
it "defaults to the :sidekiq adapter" do
|
16
|
+
MultiWorker.default_adapter.should == :sidekiq
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when using the :sidekiq adapter" do
|
21
|
+
it "performs the work using Sidekiq" do
|
22
|
+
TestWorker.perform_async("foo")
|
23
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
24
|
+
TestWorker.jobs.size.should == 2
|
25
|
+
end
|
26
|
+
|
27
|
+
it "forwards ::perform to #perform" do
|
28
|
+
expect(TestWorker).to receive(:perform).once.with("foo")
|
29
|
+
TestWorker.perform("foo")
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with advanced options" do
|
33
|
+
context "when configuring the :retry option" do
|
34
|
+
context "with a hash" do
|
35
|
+
it "configures limit and delay" do
|
36
|
+
retry_worker = Class.new do
|
37
|
+
worker :retry => {:limit => 10, :delay => lambda {|count| count*5} }
|
38
|
+
end
|
39
|
+
|
40
|
+
retry_worker.get_sidekiq_options['retry'].should == 10
|
41
|
+
retry_worker.sidekiq_retry_in_block.call(3).should == 15
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with a number" do
|
46
|
+
it "configures limit" do
|
47
|
+
retry_worker = Class.new do
|
48
|
+
worker :retry => 15
|
49
|
+
end
|
50
|
+
|
51
|
+
retry_worker.get_sidekiq_options['retry'].should == 15
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a boolean" do
|
56
|
+
it "configures retry" do
|
57
|
+
retry_worker = Class.new do
|
58
|
+
worker :retry => true
|
59
|
+
end
|
60
|
+
|
61
|
+
retry_worker.get_sidekiq_options['retry'].should == true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "configures :lock option" do
|
67
|
+
locking_worker = Class.new do
|
68
|
+
worker :lock => true
|
69
|
+
end
|
70
|
+
|
71
|
+
locking_worker.get_sidekiq_options['lock'].should == true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "configures :unique option" do
|
75
|
+
unique_worker = Class.new do
|
76
|
+
worker :unique => true
|
77
|
+
end
|
78
|
+
|
79
|
+
unique_worker.get_sidekiq_options['unique'].should == true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "configures :status option" do
|
83
|
+
status_worker = Class.new do
|
84
|
+
worker :status => true
|
85
|
+
end
|
86
|
+
|
87
|
+
status_worker.new.should be_a ::SidekiqStatus::Worker
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'sneakers'
|
2
|
+
Sneakers.configure(:env => 'test')
|
3
|
+
|
4
|
+
require 'test_workers'
|
5
|
+
|
6
|
+
describe TestWorker do
|
7
|
+
it_behaves_like "a worker"
|
8
|
+
|
9
|
+
it { should be_a ::Sneakers::Worker }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe MultiWorker do
|
13
|
+
context "when Sneakers is loaded" do
|
14
|
+
it "defaults to the :qu adapter" do
|
15
|
+
MultiWorker.default_adapter.should == :sneakers
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when using the :sneakers adapter" do
|
20
|
+
let(:worker) { TestWorker.new }
|
21
|
+
|
22
|
+
context "when calling #perform_async" do
|
23
|
+
it "publishes a message to the queue" do
|
24
|
+
expect(::Sneakers).to receive(:publish).once
|
25
|
+
worker.perform_async("foo")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when Sneakers calls #work" do
|
30
|
+
it "calls #perform" do
|
31
|
+
expect(worker).to receive(:perform).once.with("foo")
|
32
|
+
worker.work(["foo"].to_json)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'sucker_punch'
|
2
|
+
require 'sucker_punch/testing/inline'
|
3
|
+
|
4
|
+
require 'test_workers'
|
5
|
+
|
6
|
+
describe TestWorker do
|
7
|
+
it_behaves_like "a worker"
|
8
|
+
|
9
|
+
it { should be_a ::SuckerPunch::Job }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe MultiWorker do
|
13
|
+
context "when Sucker Punch is loaded" do
|
14
|
+
it "defaults to the :sucker_punch adapter" do
|
15
|
+
MultiWorker.default_adapter.should == :sucker_punch
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when using the :sucker_punch adapter" do
|
20
|
+
before(:each) do
|
21
|
+
TestWorker.any_instance.should_receive(:perform).once.with("foo")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "::perform_async uses Sucker Punch" do
|
25
|
+
TestWorker.perform_async("foo")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "MultiWorker.enqueue uses Sucker Punch" do
|
29
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "::perform delegates to #perform" do
|
33
|
+
TestWorker.perform("foo")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'threaded_in_memory_queue'
|
2
|
+
ThreadedInMemoryQueue.inline = true
|
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 ThreadedInMemoryQueue is loaded" do
|
12
|
+
it "defaults to the :threaded_in_memory_queue adapter" do
|
13
|
+
MultiWorker.default_adapter.should == :threaded_in_memory_queue
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when using the :threaded_in_memory_queue adapter" do
|
18
|
+
it "performs the work using ThreadedInMemoryQueue" 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
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
exit unless jruby?
|
2
|
+
|
3
|
+
require 'torquebox/messaging'
|
4
|
+
require 'torquebox/messaging/backgroundable'
|
5
|
+
require 'torquebox/core'
|
6
|
+
#java_import 'org.torquebox.core.util.StringUtils'
|
7
|
+
|
8
|
+
require 'test_workers'
|
9
|
+
|
10
|
+
describe TestWorker do
|
11
|
+
it_behaves_like "a worker"
|
12
|
+
|
13
|
+
it { should be_a ::TorqueBox::Messaging::Backgroundable}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe MultiWorker do
|
17
|
+
context "when TorqueBox::Messaging::Backgroundable is loaded" do
|
18
|
+
it "defaults to the :sidekiq adapter" do
|
19
|
+
MultiWorker.default_adapter.should == :torquebox_backgroundable
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when using the :torquebox_backgroundable adapter" do
|
24
|
+
it "puts a message on the queue" do
|
25
|
+
#@queue.should_receive(:publish).exactly(2).times
|
26
|
+
TorqueBox::Messaging::Backgroundable::Util.should_receive(:publish_message).exactly(2).times
|
27
|
+
TestWorker.perform_async("foo")
|
28
|
+
MultiWorker.enqueue(TestWorker, "foo")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
describe MultiWorker do
|
2
|
+
context 'configuration' do
|
3
|
+
it 'yields itself in a configuration block' do
|
4
|
+
MultiWorker.configure do
|
5
|
+
self.should == MultiWorker
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'allows the default adapter to be set' do
|
10
|
+
MultiWorker.configure do
|
11
|
+
default_adapter :foo
|
12
|
+
end
|
13
|
+
|
14
|
+
MultiWorker.default_adapter.should == :foo
|
15
|
+
|
16
|
+
MultiWorker.instance_variable_set(:@default_adapter, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'picks a default adapter automatically' do
|
20
|
+
MultiWorker.default_adapter.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'provides default options' do
|
24
|
+
MultiWorker.default_options[:queue].should == :default
|
25
|
+
MultiWorker.default_options[:retry].should == false
|
26
|
+
MultiWorker.default_options[:lock].should == false
|
27
|
+
MultiWorker.default_options[:unique].should == false
|
28
|
+
MultiWorker.default_options[:status].should == false
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'allows default options to be customized' do
|
32
|
+
MultiWorker.configure do
|
33
|
+
default_options :retry => true, :unique => true
|
34
|
+
end
|
35
|
+
|
36
|
+
MultiWorker.default_options[:retry].should == true
|
37
|
+
MultiWorker.default_options[:lock].should == false
|
38
|
+
MultiWorker.default_options[:unique].should == true
|
39
|
+
MultiWorker.default_options[:status].should == false
|
40
|
+
|
41
|
+
MultiWorker.instance_variable_set(:@default_options, nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows default options to be overriden on the worker' do
|
45
|
+
MultiWorker.configure do
|
46
|
+
default_adapter :foo
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'multi_worker/adapters/inline'
|
50
|
+
MultiWorker::Adapters::Inline.should_receive(:configure) do |klass, opts|
|
51
|
+
opts[:queue].should == :background
|
52
|
+
end
|
53
|
+
|
54
|
+
custom_worker = Class.new do
|
55
|
+
worker :adapter => :inline, :queue => :background
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|