sidekiq-delay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +8 -0
- data/lib/sidekiq/delay.rb +42 -0
- data/lib/sidekiq/delay/version.rb +5 -0
- data/sidekiq-delay.gemspec +28 -0
- data/spec/app/models/band.rb +12 -0
- data/spec/app/models/team.rb +23 -0
- data/spec/config/mongoid.yml +6 -0
- data/spec/sidekiq/delay_spec.rb +26 -0
- data/spec/spec_helper.rb +9 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 805faf90315131ee499e200e76119ee6a192cc6c
|
4
|
+
data.tar.gz: cba480e68427bab5ca9356a7c7b8650b6409f329
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd1f11f8ca93f98c9624c21b59c683546619a5f0b42735aa11c1ede4413d70cd0affb87d3da7d57cbfa0bb59cccb6cc471d95d11207f308b7e3e891d00a53f55
|
7
|
+
data.tar.gz: 633ef9b2d2516198f9c2bed475177c322b1cd67f64b6dd73e2e0a8a253ba05bfd0eeb7cf6b7e71332cfc6f06dceb2b44f56efcd6308c42b8e82df262b5d4342a
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Daniel Libanori
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Sidekiq::Delay
|
2
|
+
|
3
|
+
- [![Build Status](https://secure.travis-ci.org/dlibanori/sidekiq-delay.png)](http://travis-ci.org/dlibanori/sidekiq-delay)
|
4
|
+
- [![Code Climate](https://codeclimate.com/github/dlibanori/sidekiq-delay.png)](https://codeclimate.com/github/dlibanori/sidekiq-delay)
|
5
|
+
- [![Coverage Status](https://coveralls.io/repos/dlibanori/sidekiq-delay/badge.png)](https://coveralls.io/r/dlibanori/sidekiq-delay)
|
6
|
+
|
7
|
+
Wouldn't be nice if you could easily queue model method calls to Sidekiq? With **Sidekiq::Delay** you can!
|
8
|
+
|
9
|
+
You have just to include a module and call `delay` before any method call. Actually, your model class have to respond to some methods, but if you are using `ActiveRecord` or `Mongoid` they already do.
|
10
|
+
|
11
|
+
**NOTE**: It doesn't support `block` arguments.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'sidekiq-delay'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install sidekiq-delay
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
First you have to include `Sidekiq::Delay` at your model.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class Band
|
33
|
+
include Mongoid::Document
|
34
|
+
include Sidekiq::Delay
|
35
|
+
|
36
|
+
field :name
|
37
|
+
|
38
|
+
def play!
|
39
|
+
# it is a long task
|
40
|
+
sleep 3
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Now you can `delay` method calls to a Sidekiq queue.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
band = Band.create(name: 'Daft Punk')
|
49
|
+
band.delay.play!
|
50
|
+
```
|
51
|
+
|
52
|
+
## How it works
|
53
|
+
|
54
|
+
It queues an job with model class, model id, method name and args. Later, at Sidekiq, it finds your model using class and id and calls method with args. Your class must respond to `find(id)` and return same model.
|
55
|
+
|
56
|
+
**NOTE**: Your model must be stored at database before `delay` any call.
|
57
|
+
|
58
|
+
## Custom works
|
59
|
+
|
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
|
+
|
62
|
+
Your worker just need to include `Sidekiq::Delay::DefaultStrategy` or extend `Sidekiq::Delay::DefaultWorker`.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class TeamWorker
|
66
|
+
include Sidekiq::Worker
|
67
|
+
include Sidekiq::Delay::DefaultStrategy
|
68
|
+
|
69
|
+
def record(klass, id)
|
70
|
+
klass.custom_find(id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Team
|
75
|
+
include Mongoid::Document
|
76
|
+
include Sidekiq::Delay
|
77
|
+
|
78
|
+
worker TeamWorker
|
79
|
+
|
80
|
+
field :name
|
81
|
+
|
82
|
+
def self.custom_find(id)
|
83
|
+
find(id)
|
84
|
+
end
|
85
|
+
|
86
|
+
def play!
|
87
|
+
# it is a long task
|
88
|
+
sleep 3
|
89
|
+
end
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "sidekiq"
|
2
|
+
require "sidekiq/delay/version"
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module Sidekiq
|
6
|
+
module Delay
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
@worker = DefaultWorker
|
11
|
+
end
|
12
|
+
|
13
|
+
def delay(options={})
|
14
|
+
Sidekiq::Extensions::Proxy.new \
|
15
|
+
self.class.worker,
|
16
|
+
[ self.class, self.id ],
|
17
|
+
options
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def worker(worker=nil)
|
22
|
+
worker ? @worker = worker : @worker
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module DefaultStrategy
|
27
|
+
def perfom(yml)
|
28
|
+
((klass, id), method_name, args) = YAML.load(yml)
|
29
|
+
record.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
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/delay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sidekiq-delay"
|
8
|
+
spec.version = Sidekiq::Delay::VERSION
|
9
|
+
spec.authors = ["Daniel Libanori"]
|
10
|
+
spec.email = ["daniellibanori@gmail.com"]
|
11
|
+
spec.description = %q{Wouldn't be nice if you could directly queue your model method calls to Sidekiq? With Sidekiq::Delaty you can!}
|
12
|
+
spec.summary = %q{Queue model method calls at Sidekiq}
|
13
|
+
spec.homepage = "https://github.com/dlibanori/sidekiq-delay"
|
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_dependency "sidekiq", "~> 2.12.4"
|
22
|
+
spec.add_dependency "activesupport", "~> 3.2.13"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "mongoid"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sidekiq/delay'
|
2
|
+
|
3
|
+
class TeamWorker
|
4
|
+
include Sidekiq::Worker
|
5
|
+
include Sidekiq::Delay::DefaultStrategy
|
6
|
+
|
7
|
+
def record(klass, id)
|
8
|
+
klass.find(id)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Team
|
13
|
+
include Mongoid::Document
|
14
|
+
include Sidekiq::Delay
|
15
|
+
|
16
|
+
worker TeamWorker
|
17
|
+
|
18
|
+
def play
|
19
|
+
print 'Long running task...'
|
20
|
+
spleep 3
|
21
|
+
print ' done!'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'sidekiq/testing'
|
3
|
+
require 'app/models/band'
|
4
|
+
require 'app/models/team'
|
5
|
+
|
6
|
+
describe Sidekiq::Delay do
|
7
|
+
context "with default worker" do
|
8
|
+
let(:band) { Band.new }
|
9
|
+
|
10
|
+
it "queue an job at default queue" do
|
11
|
+
expect {
|
12
|
+
band.delay.play
|
13
|
+
}.to change(Sidekiq::Delay::DefaultWorker.jobs, :size).by(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with custom worker" do
|
18
|
+
let(:team) { Team.new }
|
19
|
+
|
20
|
+
it "queue an job at default queue" do
|
21
|
+
expect {
|
22
|
+
team.delay.play
|
23
|
+
}.to change(TeamWorker.jobs, :size).by(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-delay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Libanori
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.12.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.12.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.13
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.13
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mongoid
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Wouldn't be nice if you could directly queue your model method calls
|
98
|
+
to Sidekiq? With Sidekiq::Delaty you can!
|
99
|
+
email:
|
100
|
+
- daniellibanori@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .coveralls.yml
|
106
|
+
- .gitignore
|
107
|
+
- .travis.yml
|
108
|
+
- Gemfile
|
109
|
+
- Guardfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- lib/sidekiq/delay.rb
|
114
|
+
- lib/sidekiq/delay/version.rb
|
115
|
+
- sidekiq-delay.gemspec
|
116
|
+
- spec/app/models/band.rb
|
117
|
+
- spec/app/models/team.rb
|
118
|
+
- spec/config/mongoid.yml
|
119
|
+
- spec/sidekiq/delay_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/dlibanori/sidekiq-delay
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Queue model method calls at Sidekiq
|
145
|
+
test_files:
|
146
|
+
- spec/app/models/band.rb
|
147
|
+
- spec/app/models/team.rb
|
148
|
+
- spec/config/mongoid.yml
|
149
|
+
- spec/sidekiq/delay_spec.rb
|
150
|
+
- spec/spec_helper.rb
|