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
@@ -1,41 +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.
|
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.
|
39
|
-
end
|
40
|
-
end
|
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
|
+
expect(MultiWorker.default_adapter).to eq(: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
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("qc:work")
|
39
|
+
end
|
40
|
+
end
|
41
41
|
end
|
@@ -1,74 +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.
|
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 :
|
29
|
-
end
|
30
|
-
|
31
|
-
retry_worker.
|
32
|
-
retry_worker.instance_variable_get(:@retry_limit).
|
33
|
-
retry_worker.instance_variable_get(:@retry_delay).
|
34
|
-
end
|
35
|
-
|
36
|
-
it "configures :lock option" do
|
37
|
-
locking_worker = Class.new do
|
38
|
-
worker :
|
39
|
-
end
|
40
|
-
|
41
|
-
locking_worker.
|
42
|
-
locking_worker.instance_variable_get(:@lock_timeout).
|
43
|
-
end
|
44
|
-
|
45
|
-
it "configures :unique option with :lock" do
|
46
|
-
unique_worker = Class.new do
|
47
|
-
worker :
|
48
|
-
end
|
49
|
-
|
50
|
-
unique_worker.instance_variable_get(:@loner).
|
51
|
-
end
|
52
|
-
|
53
|
-
it "configures :unique option without :lock" do
|
54
|
-
unique_worker = Class.new do
|
55
|
-
worker :
|
56
|
-
end
|
57
|
-
|
58
|
-
unique_worker.
|
59
|
-
end
|
60
|
-
|
61
|
-
it "configures :status option" do
|
62
|
-
status_worker = Class.new do
|
63
|
-
worker :
|
64
|
-
end
|
65
|
-
|
66
|
-
status_worker.
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it "exposes the Resque rake task" do
|
71
|
-
MultiWorker.adapter.rake_task.name.
|
72
|
-
end
|
73
|
-
end
|
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
|
+
expect(MultiWorker.default_adapter).to eq(: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
|
+
expect(retry_worker).to be_a ::Resque::Plugins::Retry
|
32
|
+
expect(retry_worker.instance_variable_get(:@retry_limit)).to eq(10)
|
33
|
+
expect(retry_worker.instance_variable_get(:@retry_delay)).to eq(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
|
+
expect(locking_worker).to be_a ::Resque::Plugins::LockTimeout
|
42
|
+
expect(locking_worker.instance_variable_get(:@lock_timeout)).to eq(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
|
+
expect(unique_worker.instance_variable_get(:@loner)).to 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
|
+
expect(unique_worker).to 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
|
+
expect(status_worker).to include ::Resque::Plugins::Status
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "exposes the Resque rake task" do
|
71
|
+
expect(MultiWorker.adapter.rake_task.name).to eq("resque:work")
|
72
|
+
end
|
73
|
+
end
|
74
74
|
end
|
@@ -1,91 +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.
|
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.
|
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 :
|
38
|
-
end
|
39
|
-
|
40
|
-
retry_worker.get_sidekiq_options['retry'].
|
41
|
-
retry_worker.sidekiq_retry_in_block.call(3).
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with a number" do
|
46
|
-
it "configures limit" do
|
47
|
-
retry_worker = Class.new do
|
48
|
-
worker :
|
49
|
-
end
|
50
|
-
|
51
|
-
retry_worker.get_sidekiq_options['retry'].
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with a boolean" do
|
56
|
-
it "configures retry" do
|
57
|
-
retry_worker = Class.new do
|
58
|
-
worker :
|
59
|
-
end
|
60
|
-
|
61
|
-
retry_worker.get_sidekiq_options['retry'].
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "configures :lock option" do
|
67
|
-
locking_worker = Class.new do
|
68
|
-
worker :
|
69
|
-
end
|
70
|
-
|
71
|
-
locking_worker.get_sidekiq_options['lock'].
|
72
|
-
end
|
73
|
-
|
74
|
-
it "configures :unique option" do
|
75
|
-
unique_worker = Class.new do
|
76
|
-
worker :
|
77
|
-
end
|
78
|
-
|
79
|
-
unique_worker.get_sidekiq_options['unique'].
|
80
|
-
end
|
81
|
-
|
82
|
-
it "configures :status option" do
|
83
|
-
status_worker = Class.new do
|
84
|
-
worker :
|
85
|
-
end
|
86
|
-
|
87
|
-
status_worker.new.
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
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
|
+
expect(MultiWorker.default_adapter).to eq(: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
|
+
expect(TestWorker.jobs.size).to eq(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
|
+
expect(retry_worker.get_sidekiq_options['retry']).to eq(10)
|
41
|
+
expect(retry_worker.sidekiq_retry_in_block.call(3)).to eq(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
|
+
expect(retry_worker.get_sidekiq_options['retry']).to eq(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
|
+
expect(retry_worker.get_sidekiq_options['retry']).to eq(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
|
+
expect(locking_worker.get_sidekiq_options['lock']).to eq(true)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "configures :unique option" do
|
75
|
+
unique_worker = Class.new do
|
76
|
+
worker unique: true
|
77
|
+
end
|
78
|
+
|
79
|
+
expect(unique_worker.get_sidekiq_options['unique']).to eq(true)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "configures :status option" do
|
83
|
+
status_worker = Class.new do
|
84
|
+
worker status: true
|
85
|
+
end
|
86
|
+
|
87
|
+
expect(status_worker.new).to be_a ::SidekiqStatus::Worker
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
91
|
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'sneakers'
|
2
|
-
Sneakers.configure(:
|
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.
|
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
|
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
|
+
expect(MultiWorker.default_adapter).to eq(: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
36
|
end
|