Class: Resque::Pertry::ResquePertryPersistence
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Resque::Pertry::ResquePertryPersistence
- Defined in:
- lib/resque/pertry/resque_pertry_persistence.rb
Class Method Summary collapse
- .create_job_if_needed(klass, args) ⇒ Object
- .fail_job(klass, args) ⇒ Object
- .finnish_job(klass, args) ⇒ Object
- .trying_job(klass, args) ⇒ Object
- .with_job(klass, args, &block) ⇒ Object
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #expired? ⇒ Boolean
- #failed? ⇒ Boolean
- #finnished? ⇒ Boolean
- #payload ⇒ Object
Class Method Details
.create_job_if_needed(klass, args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 17 def create_job_if_needed(klass, args) with_job(klass, args) do |job| # we already have a job for this, we don't want another return if job # creating a new job params = { :audit_id => field_from_args('audit_id', args), :job => klass.to_s, :arguments => Resque.encode(args), :attempt => 0, :enqueued_at => field_from_args('queue_time', args) } params[:expires_at] = params[:enqueued_at] + klass.retry_ttl if klass.retry_ttl new(params).save! end end |
.fail_job(klass, args) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 55 def fail_job(klass, args) with_job(klass, args) do |job| return unless job return if job.finnished? job.update_attribute(:failed_at, Time.now) end end |
.finnish_job(klass, args) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 38 def finnish_job(klass, args) with_job(klass, args) do |job| return unless job return if job.finnished? job.update_attribute(:completed_at, Time.now) end end |
.trying_job(klass, args) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 46 def (klass, args) with_job(klass, args) do |job| return unless job return if job.finnished? job.update_attributes( :last_tried_at => Time.now, :attempt => job.attempt + 1) end end |
.with_job(klass, args, &block) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 63 def with_job(klass, args, &block) audit_id = field_from_args('audit_id', args) return unless audit_id job = find_by_audit_id(audit_id) block.call(job) if block_given? end |
Instance Method Details
#completed? ⇒ Boolean
80 81 82 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 80 def completed? completed_at end |
#expired? ⇒ Boolean
84 85 86 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 84 def expired? expires_at < Time.now end |
#failed? ⇒ Boolean
88 89 90 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 88 def failed? failed_at end |
#finnished? ⇒ Boolean
92 93 94 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 92 def finnished? completed? || failed? || expired? end |
#payload ⇒ Object
96 97 98 |
# File 'lib/resque/pertry/resque_pertry_persistence.rb', line 96 def payload @payload ||= Resque.decode(arguments) end |