Class: BatchProcessor::BatchJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
Technologic
Defined in:
lib/batch_processor/batch_job.rb

Defined Under Namespace

Classes: BatchAbortedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#batch_idObject

Returns the value of attribute batch_id.



6
7
8
# File 'lib/batch_processor/batch_job.rb', line 6

def batch_id
  @batch_id
end

#tracked_batch_failureObject

Returns the value of attribute tracked_batch_failure.



6
7
8
# File 'lib/batch_processor/batch_job.rb', line 6

def tracked_batch_failure
  @tracked_batch_failure
end

#tracked_batch_runningObject

Returns the value of attribute tracked_batch_running.



6
7
8
# File 'lib/batch_processor/batch_job.rb', line 6

def tracked_batch_running
  @tracked_batch_running
end

Instance Method Details

#batchObject



58
59
60
61
62
# File 'lib/batch_processor/batch_job.rb', line 58

def batch
  return unless batch_job?

  @batch ||= BatchProcessor::BatchBase.find(batch_id)
end

#batch_job?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/batch_processor/batch_job.rb', line 64

def batch_job?
  batch_id.present?
end

#deserialize(job_data) ⇒ Object



53
54
55
56
# File 'lib/batch_processor/batch_job.rb', line 53

def deserialize(job_data)
  super(job_data)
  self.batch_id = job_data["batch_id"]
end

#rescue_with_handler(exception) ⇒ Object

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. :(



34
35
36
37
38
39
40
41
# File 'lib/batch_processor/batch_job.rb', line 34

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_jobObject



43
44
45
46
47
# File 'lib/batch_processor/batch_job.rb', line 43

def retry_job(*)
  return if batch_job? && batch.processor_class.disable_retries?

  super
end

#serializeObject



49
50
51
# File 'lib/batch_processor/batch_job.rb', line 49

def serialize
  super.merge("batch_id" => batch_id) # rubocop:disable Style/StringHashKeys
end