Class: GoodJob::BatchRecord
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- GoodJob::BatchRecord
- Includes:
- AdvisoryLockable
- Defined in:
- app/models/good_job/batch_record.rb
Defined Under Namespace
Classes: PropertySerializer
Constant Summary
Constants included from AdvisoryLockable
AdvisoryLockable::RecordAlreadyAdvisoryLockedError
Instance Method Summary collapse
- #_continue_discard_or_finish(execution = nil, lock: true) ⇒ Object
- #display_attributes ⇒ Object
- #properties=(value) ⇒ Object
-
#succeeded? ⇒ Boolean
Whether the batch has finished and no jobs were discarded.
- #to_batch ⇒ Object
Methods included from AdvisoryLockable
#advisory_lock, #advisory_lock!, #advisory_locked?, #advisory_unlock, #advisory_unlock!, #advisory_unlocked?, #lockable_column_key, #lockable_key, #owns_advisory_lock?, #with_advisory_lock
Methods inherited from BaseRecord
bind_value, migrated?, migration_pending_warning!, with_logger_silenced
Instance Method Details
#_continue_discard_or_finish(execution = nil, lock: true) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/good_job/batch_record.rb', line 55 def _continue_discard_or_finish(execution = nil, lock: true) execution_discarded = execution && execution.finished_at.present? && execution.error.present? buffer = GoodJob::Adapter::InlineBuffer.capture do advisory_lock_maybe(lock) do Batch.within_thread(batch_id: nil, batch_callback_id: id) do reload if execution_discarded && !discarded_at update(discarded_at: Time.current) on_discard.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :discard }) if on_discard.present? end if enqueued_at && !finished_at && jobs.where(finished_at: nil).count.zero? update(finished_at: Time.current) on_success.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :success }) if !discarded_at && on_success.present? on_finish.constantize.set(priority: callback_priority, queue: callback_queue_name).perform_later(to_batch, { event: :finish }) if on_finish.present? end end end end buffer.call end |
#display_attributes ⇒ Object
51 52 53 |
# File 'app/models/good_job/batch_record.rb', line 51 def display_attributes attributes.except('serialized_properties').merge(properties: properties) end |
#properties=(value) ⇒ Object
94 95 96 97 98 |
# File 'app/models/good_job/batch_record.rb', line 94 def properties=(value) raise ArgumentError, "Properties must be a Hash" unless value.is_a?(Hash) self.serialized_properties = value end |
#succeeded? ⇒ Boolean
Whether the batch has finished and no jobs were discarded
43 44 45 |
# File 'app/models/good_job/batch_record.rb', line 43 def succeeded? !discarded? && finished? end |