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 +4 -4
- data/.simplecov +3 -0
- data/Gemfile +2 -2
- data/Guardfile +1 -1
- data/README.md +4 -4
- data/lib/sidekiq/delay.rb +3 -19
- data/lib/sidekiq/delay/strategy.rb +14 -0
- data/lib/sidekiq/delay/version.rb +1 -1
- data/lib/sidekiq/delay/worker.rb +10 -0
- data/spec/app/models/band.rb +1 -1
- data/spec/app/models/team.rb +1 -1
- data/spec/sidekiq/delay/strategy_spec.rb +35 -0
- data/spec/sidekiq/delay/worker_spec.rb +12 -0
- data/spec/sidekiq/delay_spec.rb +13 -3
- data/spec/spec_helper.rb +2 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 744b0e7a5d32a84f8d8920e70d5b9489f756434a
|
4
|
+
data.tar.gz: 7ca242145f24ee2ea4e6d83da579dcd1238a67da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03329a323bf0b17ccc7ab1d205470a6c28d7d3f1354c9aab3a97ce8f5a2bd1504d8389b4ad10ba5d98e51274bd18ff71df4638441d96b7010d5e78c46ad3488f
|
7
|
+
data.tar.gz: 7f1d6a287f223a9bd51cbfa11d97e079c0feae6f291312b335fb488c4640e415bc627bfa2f627526fcc9096639f74afdd802178910f4f780d0c93a6e7231b674
|
data/.simplecov
ADDED
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
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
|
-
#
|
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::
|
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::
|
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
|
-
#
|
87
|
+
# a long task
|
88
88
|
sleep 3
|
89
89
|
end
|
90
90
|
end
|
data/lib/sidekiq/delay.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require "sidekiq"
|
2
|
-
require "
|
3
|
-
require
|
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 =
|
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
|
data/spec/app/models/band.rb
CHANGED
data/spec/app/models/team.rb
CHANGED
@@ -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
|
data/spec/sidekiq/delay_spec.rb
CHANGED
@@ -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 "
|
16
|
+
it "queues a job at default queue" do
|
11
17
|
expect {
|
12
18
|
band.delay.play
|
13
|
-
}.to change(Sidekiq::Delay::
|
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 "
|
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)
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
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
|