Module: AsyncTask::BaseAttempt
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/async_task/base_attempt.rb
Instance Method Summary collapse
Instance Method Details
#expire! ⇒ Object
75 76 77 78 79 80 |
# File 'lib/async_task/base_attempt.rb', line 75 def expire! with_lock do raise AsyncTask::InvalidStateError unless pending? update_status!('expired') end end |
#fail! ⇒ Object
82 83 84 85 86 87 |
# File 'lib/async_task/base_attempt.rb', line 82 def fail! with_lock do raise AsyncTask::InvalidStateError unless pending? update_status!('failed') end end |
#may_schedule? ⇒ Boolean
89 90 91 |
# File 'lib/async_task/base_attempt.rb', line 89 def may_schedule? scheduled_at.blank? || scheduled_at < Time.current end |
#perform! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/async_task/base_attempt.rb', line 49 def perform! return unless may_schedule? begin reload raise AsyncTask::InvalidStateError unless pending? increment!(:num_attempts) rescue ActiveRecord::StaleObjectError retry end with_lock do raise AsyncTask::InvalidStateError unless pending? if method_args.present? target.constantize.__send__(method_name, **method_args) else target.constantize.__send__(method_name) end update_status!('succeeded') end rescue StandardError => e handle_perform_error(e) end |