class BatchProcessor::BatchJob

BatchProcessor depends on ActiveJob for handling the processing of individual items in a collection.

Attributes

batch_id[RW]
tracked_batch_failure[RW]
tracked_batch_running[RW]

Public Instance Methods

batch() click to toggle source
# File lib/batch_processor/batch_job.rb, line 60
def batch
  return unless batch_job?

  @batch ||= BatchProcessor::BatchBase.find(batch_id)
end
batch_job?() click to toggle source
# File lib/batch_processor/batch_job.rb, line 66
def batch_job?
  batch_id.present?
end
deserialize(job_data) click to toggle source
Calls superclass method
# File lib/batch_processor/batch_job.rb, line 55
def deserialize(job_data)
  super(job_data)
  self.batch_id = job_data["batch_id"]
end
rescue_with_handler(exception) click to toggle source

Some combination of Sidekiq + ActiveJob + Postgres + Deadlocks = this getting called twice for the same instance. It is unclear WHY that situation happens, but during the second execution, the instance no longer has it's job_id but somehow still has a batch ID. It seems regardless, an internal semaphore seems to prevent miscounting in that situation. I'd love to know what the root cause is behind it, but async debugging is time consuming and hard. :(

Calls superclass method
# File lib/batch_processor/batch_job.rb, line 36
def rescue_with_handler(exception)
  batch.job_canceled and return exception if exception.is_a?(BatchAbortedError)

  batch_job_failure(exception) if batch_job? && !tracked_batch_failure
  self.tracked_batch_failure = true

  super
end
retry_job(*) click to toggle source
Calls superclass method
# File lib/batch_processor/batch_job.rb, line 45
def retry_job(*)
  return if batch_job? && batch.processor_class.disable_retries?

  super
end
serialize() click to toggle source
Calls superclass method
# File lib/batch_processor/batch_job.rb, line 51
def serialize
  super.merge("batch_id" => batch_id) # rubocop:disable Style/StringHashKeys
end

Private Instance Methods

batch_job_failure(exception) click to toggle source
# File lib/batch_processor/batch_job.rb, line 72
def batch_job_failure(exception)
  error :batch_job_failed, exception: exception, job_id: job_id
  batch.job_running unless tracked_batch_running
  batch.job_failure
end