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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eff1b67f7d6f0861193b1164fd5976aa053eaa37
4
- data.tar.gz: 7d54dffeb1ce6da386919473cb194b0046658e34
3
+ metadata.gz: 58371d2a8351fc6f496e304c4e6c7907df5c9e92
4
+ data.tar.gz: fde9e1540640108d612c985814eb18e135b4646a
5
5
  SHA512:
6
- metadata.gz: bbaca27df3e2b4c4aaff3faa79658934fd846ffab3da1f76dac7d24586955983099f34e858109bb723b85b91adb31a85061e2d6165aa100e1f79d0d590369b19
7
- data.tar.gz: 688cc31e9c28ba87847fccf894dc2bf41cab53005fbe61f7b905fe44d2845df213adee4b574b4f97a6bf82c010daa452d1b69e3e332ee3cc4b63fa536628fcb5
6
+ metadata.gz: faa930571ed54febc0e974799ce547525718c0e81380052576fe0f62cd4340995642b648b806b902c2f4e5d597fd8869ba7b0a3e212d42f8d8ee443b815f7219
7
+ data.tar.gz: d7b6d3bd0fba6d269aa09e761ea678968006985659203684b73961c20b23e12dadd6ad1a80ba28ea2a08a1708bfa1e599d964d93210d6d953fadffbb444b46a7
@@ -3,8 +3,9 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - 2.1.1
6
7
  - jruby-19mode
7
8
  - rbx
8
9
  matrix:
9
10
  allow_failures:
10
- - rvm: rbx
11
+ - rvm: rbx
data/Gemfile CHANGED
@@ -3,4 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in multi_worker.gemspec
4
4
  gemspec
5
5
 
6
- #gem 'pry-debugger'
6
+ group :development do
7
+ gem 'pry'
8
+ end
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # MultiWorker [![Build Status](https://travis-ci.org/dwbutler/multi_worker.png?branch=master)](https://travis-ci.org/dwbutler/multi_worker)
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 | | ✓ | | | ✓ | ✓ | ✓ | ✓ | ✓ |
@@ -31,12 +31,12 @@ module MultiWorker
31
31
 
32
32
  def default_options(opts={})
33
33
  @default_options ||= {
34
- :adapter => default_adapter,
35
- :queue => default_queue,
36
- :status => false,
37
- :retry => false,
38
- :lock => false,
39
- :unique => false
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
@@ -10,7 +10,7 @@ module MultiWorker
10
10
  end
11
11
 
12
12
  def self.perform_async(*args)
13
- delay(:queue => @queue).perform(*args)
13
+ delay(queue: @queue).perform(*args)
14
14
  end
15
15
 
16
16
  def perform_async(*args)
@@ -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! :queue => opts[:queue]
14
+ @sidekiq_options.merge! queue: opts[:queue]
15
15
 
16
16
  if opts.has_key?(:backtrace)
17
- @sidekiq_options.merge! :backtrace => opts[:backtrace]
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!(:retry => @retry[:limit])
24
+ @sidekiq_options.merge!(retry: @retry[:limit])
25
25
  sidekiq_retry_in(&@retry[:delay])
26
26
  when true, false, Fixnum
27
- @sidekiq_options.merge!(:retry => @retry)
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!(:lock => opts[:lock])
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!(:unique => true)
40
+ @sidekiq_options.merge!(unique: true)
41
41
  end
42
42
 
43
43
  sidekiq_options @sidekiq_options
@@ -18,7 +18,7 @@ module MultiWorker
18
18
  end
19
19
 
20
20
  def self.perform_async(*args)
21
- ::Sneakers.publish(args.to_json, :to_queue => @queue)
21
+ ::Sneakers.publish(args.to_json, to_queue: @queue)
22
22
  end
23
23
 
24
24
  def perform_async(*args)
@@ -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
+
@@ -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 :work => :environment do
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
@@ -1,3 +1,3 @@
1
1
  module MultiWorker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -40,8 +40,13 @@ Gem::Specification.new do |spec|
40
40
 
41
41
  spec.add_development_dependency "qu", "0.2.0"
42
42
 
43
- spec.add_development_dependency "queue_classic" unless (RUBY_ENGINE == "jruby")
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.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
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.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
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.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
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
@@ -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.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
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
@@ -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.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
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