delayed_job_extras 0.12.2 → 0.13.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.
@@ -54,19 +54,6 @@ module Delayed
54
54
  end
55
55
  end
56
56
 
57
- def validate_with_unique
58
- validate_without_unique
59
- if self.payload_object.respond_to?(:unique?) && self.new_record?
60
- if self.payload_object.unique?
61
- if Delayed::Job.count(:all, :conditions => {:worker_class_name => self.worker_class_name, :finished_at => nil}) > 0
62
- self.errors.add_to_base("Only one #{self.worker_class_name} can be queued at a time!")
63
- end
64
- end
65
- end
66
- end
67
-
68
- alias_method_chain :validate, :unique
69
-
70
57
  def pending?
71
58
  self.started_at.nil? && self.finished_at.nil?
72
59
  end
@@ -0,0 +1,19 @@
1
+ # Rails 3 style validation:
2
+ class UniqueDJValidator < ActiveModel::Validator
3
+ def validate()
4
+
5
+ if record.payload_object.respond_to?(:unique?) && record.new_record?
6
+ if record.payload_object.unique?
7
+ if Delayed::Job.count(:all, :conditions => {:worker_class_name => record.worker_class_name, :finished_at => nil}) > 0
8
+ record.errors.add_to_base("Only one #{record.worker_class_name} can be queued at a time!")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module Delayed
16
+ class Job < ActiveRecord::Base
17
+ validates_with UniqueDJValidator
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # Rails 2 style validation:
2
+ module Delayed
3
+ class Job < ActiveRecord::Base
4
+ def validate_with_unique
5
+ validate_without_unique
6
+ if self.payload_object.respond_to?(:unique?) && self.new_record?
7
+ if self.payload_object.unique?
8
+ if Delayed::Job.count(:all, :conditions => {:worker_class_name => self.worker_class_name, :finished_at => nil}) > 0
9
+ self.errors.add_to_base("Only one #{self.worker_class_name} can be queued at a time!")
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ alias_method_chain :validate, :unique
16
+ end
17
+ end
@@ -12,4 +12,10 @@ require File.join(path, 'worker')
12
12
  require File.join(path, 'action_mailer')
13
13
 
14
14
  require File.join(path, 'hoptoad')
15
- # require File.join(path, 'acts_as_paranoid')
15
+ # require File.join(path, 'acts_as_paranoid')
16
+
17
+ if Rails.version.match(/^2/)
18
+ require File.join(path, 'validate_with_unique')
19
+ else
20
+ require File.join(path, 'unique_dj_validator')
21
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 12
8
- - 2
9
- version: 0.12.2
7
+ - 13
8
+ - 0
9
+ version: 0.13.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - markbates
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-13 00:00:00 -04:00
17
+ date: 2010-05-07 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,8 @@ files:
45
45
  - lib/delayed_job_extras/hoptoad.rb
46
46
  - lib/delayed_job_extras/job.rb
47
47
  - lib/delayed_job_extras/performable_method.rb
48
+ - lib/delayed_job_extras/unique_dj_validator.rb
49
+ - lib/delayed_job_extras/validate_with_unique.rb
48
50
  - lib/delayed_job_extras/worker.rb
49
51
  - lib/delayed_job_extras.rb
50
52
  - lib/delayed_job_test_enhancements.rb