Class: UniqueDJValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- UniqueDJValidator
- Defined in:
- lib/delayed_job_extras/unique_dj_validator.rb
Overview
Rails 3 style validation:
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/delayed_job_extras/unique_dj_validator.rb', line 3 def validate(record) if record.payload_object.respond_to?(:unique?) && record.new_record? if record.payload_object.unique? if Delayed::Job.where(:worker_class_name => 'self.worker_class_name', :finished_at => nil).count > 0 record.errors.add_to_base("Only one #{record.worker_class_name} can be queued at a time!") end end end end |