resque_empty_queue 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +21 -0
- data/README.markdown +4 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/resque/empty_queue.rb +5 -0
- data/lib/resque/empty_queue_job.rb +11 -0
- data/lib/resque/empty_queue_retry_job.rb +19 -0
- data/lib/resque/resque.rb +36 -0
- data/lib/resque_empty_queue.rb +6 -0
- data/resque_empty_queue.gemspec +67 -0
- data/test/resque/resque_test.rb +32 -0
- data/test/test_helper.rb +33 -0
- metadata +142 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 Zendesk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "resque_empty_queue"
|
8
|
+
gem.summary = 'resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.'
|
9
|
+
gem.description = 'resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.'
|
10
|
+
gem.email = "michael.pearce@bookrenter.com"
|
11
|
+
gem.homepage = "http://github.com/michaelgpearce/resque_empty_queue"
|
12
|
+
gem.authors = ["Michael G. Pearce", "J. A. Wheeler"]
|
13
|
+
gem.add_dependency "resque", ">=1.6.0"
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
+
gem.add_development_dependency "mocha", ">=0.9.8"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "resque_empty_queue #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Resque
|
2
|
+
class EmptyQueueRetryJob
|
3
|
+
@queue = :resque_empty_queue
|
4
|
+
|
5
|
+
def self.perform(empty_queue_job_class_name, *args)
|
6
|
+
klass = eval(empty_queue_job_class_name)
|
7
|
+
if queue_is_empty?(klass)
|
8
|
+
Resque.enqueue(klass, *args)
|
9
|
+
else
|
10
|
+
# TODO: use resque-scheduler to enqueue in the future
|
11
|
+
Resque.enqueue_in(5, self, klass.name, *args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.queue_is_empty?(klass)
|
16
|
+
return Resque.size(klass.queue_name) == 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "resque/empty_queue"
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# Raised when trying to create a job that does not yet have an empty associated job queue
|
7
|
+
class EmptyQueueError < RuntimeError;
|
8
|
+
end
|
9
|
+
|
10
|
+
def enqueue_with_empty_queue(klass, *args)
|
11
|
+
if !empty_queue_job?(klass) || should_execute_empty_queue_job?(klass, *args)
|
12
|
+
enqueue_without_empty_queue(klass, *args)
|
13
|
+
else
|
14
|
+
# queue not empty
|
15
|
+
enqueue_without_empty_queue(EmptyQueueRetryJob, klass.name, *args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :enqueue_without_empty_queue, :enqueue
|
20
|
+
alias_method :enqueue, :enqueue_with_empty_queue
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def should_execute_empty_queue_job?(klass, *args)
|
25
|
+
return true if queue_is_empty?(klass)
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
|
29
|
+
def queue_is_empty?(klass)
|
30
|
+
return Resque.size(klass.queue_name) == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty_queue_job?(klass)
|
34
|
+
klass.ancestors.include?(Resque::EmptyQueueJob)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'resque_empty_queue'
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ['Michael G. Pearce', 'J. A. Wheeler']
|
12
|
+
s.date = '2010-07-07'
|
13
|
+
s.description = 'resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.'
|
14
|
+
s.email = %q{michael.pearce@bookrenter.com, andrew.wheeler@bookrenter.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/resque_empty_queue.rb",
|
27
|
+
"lib/resque/resque.rb",
|
28
|
+
"lib/resque/empty_queue.rb",
|
29
|
+
"lib/resque/empty_queue_job.rb",
|
30
|
+
"lib/resque/empty_queue_retry_job.rb",
|
31
|
+
"resque_empty_queue.gemspec",
|
32
|
+
"test/resque/resque_test.rb",
|
33
|
+
"test/test_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = 'http://github.com/michaelgpearce/resque_empty_queue'
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = 'resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.'
|
40
|
+
s.test_files = [
|
41
|
+
"test/resque/resque_test.rb",
|
42
|
+
"test/test_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<resque>, [">= 1.6.0"])
|
51
|
+
s.add_runtime_dependency(%q<resque-scheduler>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<resque>, [">= 1.6.0"])
|
56
|
+
s.add_dependency(%q<resque-scheduler>, [">= 0"])
|
57
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
58
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<resque>, [">= 1.6.0"])
|
62
|
+
s.add_dependency(%q<resque-scheduler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class ResqueTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Resque" do
|
6
|
+
setup do
|
7
|
+
Resque.redis.flushall
|
8
|
+
@bogus_args = "bogus_arg"
|
9
|
+
end
|
10
|
+
|
11
|
+
context "#enqueue" do
|
12
|
+
|
13
|
+
context "the queue is not empty" do
|
14
|
+
setup do
|
15
|
+
Resque.enqueue(QueuedJob, @bogus_args)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not add another job to the queue and raise an exception" do
|
19
|
+
assert_raises(Resque::EmptyQueueError) { Resque.enqueue(DefaultEmptyQueueJob, @bogus_args) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "the queue is empty" do
|
24
|
+
should "raise an exception on a duplicate indentifier" do
|
25
|
+
Resque.expects(:enqueue_without_empty_queue).once
|
26
|
+
Resque.enqueue(DefaultEmptyQueueJob, @bogus_args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'resque/resque'
|
9
|
+
require 'resque/empty_queue'
|
10
|
+
require 'resque/empty_queue_job'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
end
|
14
|
+
|
15
|
+
#fixture classes
|
16
|
+
class DefaultEmptyQueueJob < Resque::EmptyQueueJob
|
17
|
+
wait_for_empty_queue :some_queue
|
18
|
+
@queue = :empty_queue
|
19
|
+
|
20
|
+
def self.perform(some_id, some_other_thing)
|
21
|
+
puts "default empty queue perform"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class QueuedJob
|
26
|
+
@queue = :some_queue
|
27
|
+
|
28
|
+
def self.perform(some_id, some_other_thing)
|
29
|
+
sleep(2)
|
30
|
+
puts "queued job perform"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque_empty_queue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael G. Pearce
|
14
|
+
- J. A. Wheeler
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-07-07 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: resque
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 15
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 6
|
34
|
+
- 0
|
35
|
+
version: 1.6.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: resque-scheduler
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: thoughtbot-shoulda
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: mocha
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 43
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 9
|
78
|
+
- 8
|
79
|
+
version: 0.9.8
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
82
|
+
description: resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.
|
83
|
+
email: michael.pearce@bookrenter.com, andrew.wheeler@bookrenter.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE
|
90
|
+
- README.markdown
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .gitignore
|
94
|
+
- LICENSE
|
95
|
+
- README.markdown
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- lib/resque_empty_queue.rb
|
99
|
+
- lib/resque/resque.rb
|
100
|
+
- lib/resque/empty_queue.rb
|
101
|
+
- lib/resque/empty_queue_job.rb
|
102
|
+
- lib/resque/empty_queue_retry_job.rb
|
103
|
+
- resque_empty_queue.gemspec
|
104
|
+
- test/resque/resque_test.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/michaelgpearce/resque_empty_queue
|
108
|
+
licenses: []
|
109
|
+
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options:
|
112
|
+
- --charset=UTF-8
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.3.7
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: resque_empty_queue is an extension to the Resque queue system runs a job after a queue has been emptied.
|
140
|
+
test_files:
|
141
|
+
- test/resque/resque_test.rb
|
142
|
+
- test/test_helper.rb
|