sidekiq-delay 1.0.0 → 1.0.1

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: fa257722d3cdc168a74ac49bf2d9dbfdad15299a
4
- data.tar.gz: 7c51370d114aba1a1784bcd9e93a47a202fa609f
3
+ metadata.gz: 744b0e7a5d32a84f8d8920e70d5b9489f756434a
4
+ data.tar.gz: 7ca242145f24ee2ea4e6d83da579dcd1238a67da
5
5
  SHA512:
6
- metadata.gz: 79842819024351dd00eae294890f8b06a10613176db1d1b3e8640d9bef891fc4e97707a21e71b3000506db976f5e338e8f260c88e0797954d4ba0d38ecdee54d
7
- data.tar.gz: 24d9bac663bed6097aba8e9423334539dd0dffddfc33e52ac0d2a2cae3695ee3faa0e5b7f97fca84ffb2e683b21957777b1dc229c9d994ea686aee5d68f432dc
6
+ metadata.gz: 03329a323bf0b17ccc7ab1d205470a6c28d7d3f1354c9aab3a97ce8f5a2bd1504d8389b4ad10ba5d98e51274bd18ff71df4638441d96b7010d5e78c46ad3488f
7
+ data.tar.gz: 7f1d6a287f223a9bd51cbfa11d97e079c0feae6f291312b335fb488c4640e415bc627bfa2f627526fcc9096639f74afdd802178910f4f780d0c93a6e7231b674
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ add_filter "/app/"
3
+ end
data/Gemfile CHANGED
@@ -4,9 +4,9 @@ source 'https://rubygems.org'
4
4
  # Specify your gem's dependencies in sidekiq-delay.gemspec
5
5
  gemspec
6
6
 
7
- gem 'coveralls', require: false
8
-
9
7
  group :test do
8
+ gem 'simplecov', require: false
9
+ gem 'coveralls', require: false
10
10
  gem "guard-rspec"
11
11
  gem "rb-fsevent", require: false
12
12
  end
data/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard :rspec do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
9
 
data/README.md CHANGED
@@ -36,7 +36,7 @@ First you have to include `Sidekiq::Delay` at your model.
36
36
  field :name
37
37
 
38
38
  def play!
39
- # it is a long task
39
+ # a long task
40
40
  sleep 3
41
41
  end
42
42
  end
@@ -59,12 +59,12 @@ It queues an job with model class, model id, method name and args. Later, at Sid
59
59
 
60
60
  What if you class doesn't respond to `find` or you want to use another `Sidekiq` plugin? You can easily write an **custom worker**. You have just to set your model to use it with `worker` method.
61
61
 
62
- Your worker just need to include `Sidekiq::Delay::DefaultStrategy` or extend `Sidekiq::Delay::DefaultWorker`.
62
+ Your worker just need to include `Sidekiq::Delay::Strategy` or extend `Sidekiq::Delay::Worker`.
63
63
 
64
64
  ```ruby
65
65
  class TeamWorker
66
66
  include Sidekiq::Worker
67
- include Sidekiq::Delay::DefaultStrategy
67
+ include Sidekiq::Delay::Strategy
68
68
 
69
69
  def record(klass, id)
70
70
  klass.custom_find(id)
@@ -84,7 +84,7 @@ Your worker just need to include `Sidekiq::Delay::DefaultStrategy` or extend `Si
84
84
  end
85
85
 
86
86
  def play!
87
- # it is a long task
87
+ # a long task
88
88
  sleep 3
89
89
  end
90
90
  end
@@ -1,13 +1,13 @@
1
1
  require "sidekiq"
2
- require "sidekiq/delay/version"
3
- require 'active_support/concern'
2
+ require "active_support/concern"
3
+ require "sidekiq/delay/worker"
4
4
 
5
5
  module Sidekiq
6
6
  module Delay
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- @worker = DefaultWorker
10
+ @worker = Worker
11
11
  end
12
12
 
13
13
  def delay(options={})
@@ -22,21 +22,5 @@ module Sidekiq
22
22
  worker ? @worker = worker : @worker
23
23
  end
24
24
  end
25
-
26
- module DefaultStrategy
27
- def perform(yml)
28
- ((klass, id), method_name, args) = YAML.load(yml)
29
- record(klass, id).send(method_name, *args)
30
- end
31
-
32
- def record(klass, id)
33
- klass.find(id)
34
- end
35
- end
36
-
37
- class DefaultWorker
38
- include Sidekiq::Worker
39
- include DefaultStrategy
40
- end
41
25
  end
42
26
  end
@@ -0,0 +1,14 @@
1
+ module Sidekiq
2
+ module Delay
3
+ module Strategy
4
+ def perform(yml)
5
+ ((klass, id), method_name, args) = YAML.load(yml)
6
+ record(klass, id).send(method_name, *args)
7
+ end
8
+
9
+ def record(klass, id)
10
+ klass.find(id)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Delay
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ require "sidekiq/delay/strategy"
2
+
3
+ module Sidekiq
4
+ module Delay
5
+ class Worker
6
+ include Sidekiq::Worker
7
+ include Strategy
8
+ end
9
+ end
10
+ end
@@ -6,7 +6,7 @@ class Band
6
6
 
7
7
  def play
8
8
  print 'Long running task...'
9
- spleep 3
9
+ sleep 3
10
10
  print ' done!'
11
11
  end
12
12
  end
@@ -2,7 +2,7 @@ require 'sidekiq/delay'
2
2
 
3
3
  class TeamWorker
4
4
  include Sidekiq::Worker
5
- include Sidekiq::Delay::DefaultStrategy
5
+ include Sidekiq::Delay::Strategy
6
6
 
7
7
  def record(klass, id)
8
8
  klass.find(id)
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+ require "sidekiq/delay/strategy"
3
+
4
+ describe Sidekiq::Delay::Strategy do
5
+ Game = Class.new
6
+ GameWorker = Class.new { include Sidekiq::Delay::Strategy }
7
+
8
+ subject(:worker) { GameWorker.new }
9
+
10
+ let(:game) { mock "Game", play: nil }
11
+ let(:yml) { YAML.dump([[ Game, 1 ], :play, [ "get lucky", 10, 20 ]]) }
12
+
13
+ context "#perfom" do
14
+ before { worker.stub(record: game) }
15
+
16
+ it "calls record to find instance" do
17
+ worker.should_receive(:record).with(Game, 1)
18
+ worker.perform(yml)
19
+ end
20
+
21
+ it "calls play on instance" do
22
+ game.should_receive(:play).with("get lucky", 10, 20)
23
+ worker.perform(yml)
24
+ end
25
+ end
26
+
27
+ context "#record" do
28
+ before { Game.stub(find: game) }
29
+
30
+ it "finds an instance at class" do
31
+ Game.should_receive(:find).with(1)
32
+ worker.record(Game, 1)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+ require "sidekiq/delay/worker"
3
+
4
+ describe Sidekiq::Delay::Worker do
5
+ subject { described_class }
6
+
7
+ let(:strategy) { Sidekiq::Delay::Strategy }
8
+ let(:worker) { Sidekiq::Worker }
9
+
10
+ its(:ancestors) { should include(strategy) }
11
+ its(:ancestors) { should include(worker) }
12
+ end
@@ -1,23 +1,33 @@
1
1
  require "spec_helper"
2
2
  require 'sidekiq/testing'
3
+
4
+ require 'sidekiq/delay'
3
5
  require 'app/models/band'
4
6
  require 'app/models/team'
5
7
 
6
8
  describe Sidekiq::Delay do
7
9
  context "with default worker" do
10
+ subject { Band }
8
11
  let(:band) { Band.new }
12
+ let(:worker) { Sidekiq::Delay::Worker }
13
+
14
+ its(:worker) { should eq(worker) }
9
15
 
10
- it "queue an job at default queue" do
16
+ it "queues a job at default queue" do
11
17
  expect {
12
18
  band.delay.play
13
- }.to change(Sidekiq::Delay::DefaultWorker.jobs, :size).by(1)
19
+ }.to change(Sidekiq::Delay::Worker.jobs, :size).by(1)
14
20
  end
15
21
  end
16
22
 
17
23
  context "with custom worker" do
24
+ subject { Team }
18
25
  let(:team) { Team.new }
26
+ let(:worker) { TeamWorker }
27
+
28
+ its(:worker) { should eq(worker) }
19
29
 
20
- it "queue an job at default queue" do
30
+ it "queues a job at custom queue" do
21
31
  expect {
22
32
  team.delay.play
23
33
  }.to change(TeamWorker.jobs, :size).by(1)
@@ -1,6 +1,7 @@
1
- require 'coveralls'
2
1
  require 'sidekiq'
3
2
  require 'mongoid'
3
+ require 'simplecov'
4
+ require 'coveralls'
4
5
 
5
6
  Coveralls.wear!
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-delay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Libanori
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - .coveralls.yml
106
106
  - .gitignore
107
+ - .simplecov
107
108
  - .travis.yml
108
109
  - Gemfile
109
110
  - Guardfile
@@ -111,11 +112,15 @@ files:
111
112
  - README.md
112
113
  - Rakefile
113
114
  - lib/sidekiq/delay.rb
115
+ - lib/sidekiq/delay/strategy.rb
114
116
  - lib/sidekiq/delay/version.rb
117
+ - lib/sidekiq/delay/worker.rb
115
118
  - sidekiq-delay.gemspec
116
119
  - spec/app/models/band.rb
117
120
  - spec/app/models/team.rb
118
121
  - spec/config/mongoid.yml
122
+ - spec/sidekiq/delay/strategy_spec.rb
123
+ - spec/sidekiq/delay/worker_spec.rb
119
124
  - spec/sidekiq/delay_spec.rb
120
125
  - spec/spec_helper.rb
121
126
  homepage: https://github.com/dlibanori/sidekiq-delay
@@ -146,5 +151,7 @@ test_files:
146
151
  - spec/app/models/band.rb
147
152
  - spec/app/models/team.rb
148
153
  - spec/config/mongoid.yml
154
+ - spec/sidekiq/delay/strategy_spec.rb
155
+ - spec/sidekiq/delay/worker_spec.rb
149
156
  - spec/sidekiq/delay_spec.rb
150
157
  - spec/spec_helper.rb