resque_empty_queue 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -0,0 +1,54 @@
1
+ module Resque
2
+ module Plugins
3
+ class EmptyQueueFailureDetectedError < RuntimeError;
4
+ end
5
+
6
+ module EmptyQueueJob
7
+ def queue
8
+ :empty_queue
9
+ end
10
+
11
+ def wait_for_empty_queue(queue_name)
12
+ @queue_name = queue_name
13
+ end
14
+
15
+ def queue_name
16
+ return @queue_name
17
+ end
18
+
19
+ def before_perform_empty_queue_job(*args)
20
+ if !failure_queue_empty?
21
+ # should this re-enqueue itself or simply continue to retry
22
+ raise EmptyQueueFailureDetectedError.new("Failure detected in queue: #{queue_name}. Retry after jobs placed in queue.")
23
+ end
24
+
25
+ if !job_queue_empty? || !working_queue_empty?
26
+ # try again later
27
+ Resque.enqueue_in(5, self, *args)
28
+ raise Resque::Job::DontPerform
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def job_queue_empty?
35
+ return Resque.size(queue_name) == 0
36
+ end
37
+
38
+ def working_queue_empty?
39
+ return Resque::Worker.all.all? { |worker| worker.job['queue'] != queue_name.to_s }
40
+ end
41
+
42
+ def failure_queue_empty?
43
+ i = 0
44
+ page_size = 100
45
+ while !(failures = Resque::Failure.all(i, i + page_size)).empty?
46
+ return false unless failures.all? { |failure| failure.nil? || failure['retried_at'] || failure['queue'] != queue_name.to_s }
47
+ i = i + page_size
48
+ end
49
+
50
+ return true
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,5 @@
1
- require 'resque_scheduler'
1
+ require 'resque'
2
+ # Causes problems when included with Sinatra?? when loading workers rake task
3
+ # require 'resque_scheduler'
2
4
 
3
- require "resque/resque"
4
- require "resque/empty_queue"
5
- require "resque/empty_queue_job"
6
- require "resque/empty_queue_retry_job"
5
+ require "resque/plugins/empty_queue_job"
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'resque_empty_queue'
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ['Michael G. Pearce', 'J. A. Wheeler']
@@ -24,10 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
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",
27
+ "lib/resque/plugins/empty_queue_job.rb",
31
28
  "resque_empty_queue.gemspec",
32
29
  "test/resque/resque_test.rb",
33
30
  "test/test_helper.rb"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_empty_queue
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael G. Pearce
@@ -96,10 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - VERSION
98
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
99
+ - lib/resque/plugins/empty_queue_job.rb
103
100
  - resque_empty_queue.gemspec
104
101
  - test/resque/resque_test.rb
105
102
  - test/test_helper.rb
@@ -1,5 +0,0 @@
1
- require 'resque'
2
-
3
- module Resque
4
- end
5
-
@@ -1,11 +0,0 @@
1
- module Resque
2
- class EmptyQueueJob
3
- def self.wait_for_empty_queue(queue_name)
4
- @queue_name = queue_name
5
- end
6
-
7
- def self.queue_name
8
- return @queue_name
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
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
data/lib/resque/resque.rb DELETED
@@ -1,36 +0,0 @@
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