resque-timely 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/Gemfile +8 -0
- data/License.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/lib/resque-timely.rb +2 -0
- data/lib/resque/plugins/timely.rb +23 -0
- data/resque-timely.gemspec +24 -0
- data/test/resque_timely_spec.rb +24 -0
- data/test/test_helper.rb +69 -0
- metadata +119 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tony Amoyal
|
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,45 @@
|
|
1
|
+
# Resque Timely
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem "resque-timely"
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle install
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install resque-timely
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Resque Timely requires you to do two things:
|
20
|
+
|
21
|
+
1. Include Resque::Plugins::Timely in your Resque Job class
|
22
|
+
2. Implement the timely_timeout class method to return the timeout in seconds
|
23
|
+
|
24
|
+
For example:
|
25
|
+
```ruby
|
26
|
+
class YourTimelyJob
|
27
|
+
include Resque::Plugins::Timely
|
28
|
+
|
29
|
+
def self.timely_timeout
|
30
|
+
3 # 3 seconds
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Requirements
|
36
|
+
|
37
|
+
Resque Timeout will only work with 1.9.x and above. Specifically it's tested with 1.9.3.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
module Plugins
|
5
|
+
module Timely
|
6
|
+
|
7
|
+
def self.included base
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def around_perform_with_timeout *args
|
13
|
+
if respond_to? :timely_timeout
|
14
|
+
::Timeout.timeout(timely_timeout){ yield }
|
15
|
+
else
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "resque-timely"
|
7
|
+
s.version = "0.1.0"
|
8
|
+
s.authors = ["Tony Amoyal"]
|
9
|
+
s.email = "tonyamoyal@gmail.com"
|
10
|
+
s.description = "Set time limits on Resque jobs per Job class."
|
11
|
+
s.summary = "For Resque jobs that need a time limit"
|
12
|
+
s.homepage = "http://github.com/getsidewalk/resque-timely"
|
13
|
+
s.license = "MIT"
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "resque", "~>1.0"
|
21
|
+
s.add_dependency "json"
|
22
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../test_helper.rb", __FILE__)
|
2
|
+
|
3
|
+
describe Resque::Plugins::Timely do
|
4
|
+
it "times out when timely but too slow" do
|
5
|
+
->{
|
6
|
+
Resque.enqueue PoorlyBehavedTimelyJob
|
7
|
+
}.must_raise Timeout::Error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "doesn't time out when timely but fast enough" do
|
11
|
+
Resque.enqueue WellBehavedTimelyJob
|
12
|
+
WellBehavedTimelyJob.some_state.must_equal "anything but something"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesn't act timely if the module is not included" do
|
16
|
+
Resque.enqueue UntimelyJob
|
17
|
+
UntimelyJob.some_state.must_equal "anything but something"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't act timely if the timely_timeout method is not implemented" do
|
21
|
+
Resque.enqueue ConfusedJob
|
22
|
+
ConfusedJob.some_state.must_equal "anything but something"
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
|
5
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
6
|
+
require "resque-timely"
|
7
|
+
|
8
|
+
require "minitest/autorun"
|
9
|
+
|
10
|
+
Resque.inline = true
|
11
|
+
|
12
|
+
class PoorlyBehavedTimelyJob
|
13
|
+
include Resque::Plugins::Timely
|
14
|
+
@queue = :poorly_behaved
|
15
|
+
|
16
|
+
def self.timely_timeout
|
17
|
+
1.9
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.perform
|
21
|
+
sleep 2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class WellBehavedTimelyJob
|
26
|
+
include Resque::Plugins::Timely
|
27
|
+
@queue = :well_behaved
|
28
|
+
@some_state = nil
|
29
|
+
|
30
|
+
def self.some_state
|
31
|
+
@some_state
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.timely_timeout
|
35
|
+
3
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.perform
|
39
|
+
sleep 2
|
40
|
+
@some_state = "anything but something"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class UntimelyJob
|
45
|
+
@queue = :untimely
|
46
|
+
@some_state = nil
|
47
|
+
|
48
|
+
def self.some_state
|
49
|
+
@some_state
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.perform
|
53
|
+
@some_state = "anything but something"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ConfusedJob
|
58
|
+
include Resque::Plugins::Timely
|
59
|
+
@queue = :confused
|
60
|
+
@some_state = nil
|
61
|
+
|
62
|
+
def self.some_state
|
63
|
+
@some_state
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.perform
|
67
|
+
@some_state = "anything but something"
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-timely
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tony Amoyal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: resque
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Set time limits on Resque jobs per Job class.
|
79
|
+
email: tonyamoyal@gmail.com
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- Gemfile
|
86
|
+
- License.txt
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- lib/resque-timely.rb
|
90
|
+
- lib/resque/plugins/timely.rb
|
91
|
+
- resque-timely.gemspec
|
92
|
+
- test/resque_timely_spec.rb
|
93
|
+
- test/test_helper.rb
|
94
|
+
homepage: http://github.com/getsidewalk/resque-timely
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.23
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: For Resque jobs that need a time limit
|
119
|
+
test_files: []
|