resque-timeout 1.0.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.
@@ -0,0 +1,16 @@
1
+ resque-timeout
2
+ ====
3
+
4
+ Resque plugin to allow long-running jobs to timeout (and fail) automatically.
5
+
6
+ To install:
7
+
8
+ $ gem install resque-timeout
9
+
10
+ To set the timeout (in seconds, default is 600):
11
+
12
+ Resque::Plugins::Timeout.timeout = 60
13
+
14
+ To turn it off (it is on by default):
15
+
16
+ Resque::Plugins::Timeout.switch = :off
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "resque-timeout"
8
+ gem.summary = "Timeout for long-running jobs in Resque"
9
+ gem.description = 'Resque plugin allowing long-running jobs to automatically fail after a specified time.'
10
+ gem.email = "jeff.gran@gmail.com"
11
+ gem.homepage = "http://github.com/jeffgran/resque-timeout"
12
+ gem.authors = ["Jeff Gran"]
13
+ gem.add_dependency "resque", "~>1.0"
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "resque-fairly #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'resque', :version => '~> 1.0'
3
+ require 'resque'
4
+
5
+ require File.expand_path('resque/plugins/timeout', File.dirname(__FILE__))
6
+
7
+
@@ -0,0 +1,44 @@
1
+ require 'resque/worker'
2
+ require 'timeout'
3
+
4
+ module Resque::Plugins
5
+ module Timeout
6
+
7
+ def self.switch
8
+ @switch ||= :on
9
+ end
10
+
11
+ def self.switch=(val)
12
+ @switch = val
13
+ end
14
+
15
+ def self.timeout
16
+ @timeout ||= 600
17
+ end
18
+
19
+ def self.timeout=(val)
20
+ @timeout = val
21
+ end
22
+
23
+ def around_perform_with_timeout(*args)
24
+ ::Timeout.timeout(Resque::Plugins::Timeout.timeout) do
25
+ yield
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ # inject the Timeout mixin into the job class right before it
32
+ # executes (if it's not already there). This will give it the
33
+ # `around_perform_...` method above which wraps the execution
34
+ # in the ::Timeout.timeout block
35
+ Resque.before_fork do |job|
36
+ if Resque::Plugins::Timeout.switch == :on &&
37
+ !(job.payload_class.kind_of?(Resque::Plugins::Timeout))
38
+ job.payload_class.send(:extend, Resque::Plugins::Timeout)
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{resque-timeout}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeff Gran"]
12
+ s.date = %q{2011-03-07}
13
+ s.description = %q{Resque plugin allowing long-running jobs to automatically fail after a specified time.}
14
+ s.email = %q{jeff.gran@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "README.md",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/resque-timeout.rb",
23
+ "lib/resque/plugins/timeout.rb",
24
+ "resque-timeout.gemspec",
25
+ "spec/resque-timeout_spec.rb",
26
+ "spec/resque/plugins/timeout_spec.rb",
27
+ "spec/spec.opts",
28
+ "spec/spec_helper.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/jeffgran/resque-timeout}
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{Timeout for long-running jobs in Resque}
34
+ s.test_files = [
35
+ "spec/resque-timeout_spec.rb",
36
+ "spec/resque/plugins/timeout_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<resque>, ["~> 1.0"])
46
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
47
+ else
48
+ s.add_dependency(%q<resque>, ["~> 1.0"])
49
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<resque>, ["~> 1.0"])
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ResqueTimeout" do
4
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
2
+
3
+ class TestJob
4
+ def self.perform
5
+ 1.upto 5 do
6
+ putc '+'
7
+ sleep(1)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe Resque::Plugins::Timeout do
13
+ it "kills jobs that run past the time limit" do
14
+ # set up the timeout
15
+ Resque::Plugins::Timeout.timeout = 2
16
+
17
+ # create a job
18
+ Resque::Job.create('queueZ', TestJob)
19
+
20
+ # create a worker and get the job
21
+ worker = Resque::Worker.new('queueZ')
22
+ job = Resque::Job.reserve('queueZ')
23
+
24
+ # mimic the forking and running of the job (with plugin hooks)
25
+ worker.run_hook :before_fork, job
26
+ worker.process(job)
27
+
28
+ worker.failed.should == 1
29
+ end
30
+
31
+ it 'should not timeout if the plugin is turned off' do
32
+ # turn it off
33
+ Resque::Plugins::Timeout.switch = :off
34
+
35
+ # create a job
36
+ Resque::Job.create('queueZ', TestJob)
37
+
38
+ # create a worker and get the job
39
+ worker = Resque::Worker.new('queueZ')
40
+ job = Resque::Job.reserve('queueZ')
41
+
42
+ # mimic the forking and running of the job (with plugin hooks)
43
+ worker.run_hook :before_fork, job
44
+ worker.process(job)
45
+
46
+ worker.failed.should == 1
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ --diff c
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'resque-timeout'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-timeout
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jeff Gran
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-07 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: resque
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 13
45
+ segments:
46
+ - 1
47
+ - 2
48
+ - 9
49
+ version: 1.2.9
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: Resque plugin allowing long-running jobs to automatically fail after a specified time.
53
+ email: jeff.gran@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - README.md
60
+ files:
61
+ - README.md
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/resque-timeout.rb
65
+ - lib/resque/plugins/timeout.rb
66
+ - resque-timeout.gemspec
67
+ - spec/resque-timeout_spec.rb
68
+ - spec/resque/plugins/timeout_spec.rb
69
+ - spec/spec.opts
70
+ - spec/spec_helper.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/jeffgran/resque-timeout
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.7
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Timeout for long-running jobs in Resque
105
+ test_files:
106
+ - spec/resque-timeout_spec.rb
107
+ - spec/resque/plugins/timeout_spec.rb
108
+ - spec/spec_helper.rb