Class: BatchProcessor::BatchJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- BatchProcessor::BatchJob
- Includes:
- Technologic
- Defined in:
- lib/batch_processor/batch_job.rb
Overview
BatchProcessor depends on ActiveJob for handling the processing of individual items in a collection.
Direct Known Subclasses
Defined Under Namespace
Classes: BatchAbortedError
Instance Attribute Summary collapse
-
#batch_id ⇒ Object
Returns the value of attribute batch_id.
-
#tracked_batch_failure ⇒ Object
Returns the value of attribute tracked_batch_failure.
-
#tracked_batch_running ⇒ Object
Returns the value of attribute tracked_batch_running.
Instance Method Summary collapse
- #batch ⇒ Object
- #batch_job? ⇒ Boolean
- #deserialize(job_data) ⇒ Object
-
#rescue_with_handler(exception) ⇒ Object
Some combination of Sidekiq + ActiveJob + Postgres + Deadlocks = this getting called twice for the same instance.
- #retry_job ⇒ Object
- #serialize ⇒ Object
Instance Attribute Details
#batch_id ⇒ Object
Returns the value of attribute batch_id.
8 9 10 |
# File 'lib/batch_processor/batch_job.rb', line 8 def batch_id @batch_id end |
#tracked_batch_failure ⇒ Object
Returns the value of attribute tracked_batch_failure.
8 9 10 |
# File 'lib/batch_processor/batch_job.rb', line 8 def tracked_batch_failure @tracked_batch_failure end |
#tracked_batch_running ⇒ Object
Returns the value of attribute tracked_batch_running.
8 9 10 |
# File 'lib/batch_processor/batch_job.rb', line 8 def tracked_batch_running @tracked_batch_running end |
Instance Method Details
#batch ⇒ Object
60 61 62 63 64 |
# File 'lib/batch_processor/batch_job.rb', line 60 def batch return unless batch_job? @batch ||= BatchProcessor::BatchBase.find(batch_id) end |
#batch_job? ⇒ Boolean
66 67 68 |
# File 'lib/batch_processor/batch_job.rb', line 66 def batch_job? batch_id.present? end |
#deserialize(job_data) ⇒ Object
55 56 57 58 |
# 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) ⇒ 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. :(
36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
45 46 47 48 49 |
# File 'lib/batch_processor/batch_job.rb', line 45 def retry_job(*) return if batch_job? && batch.processor_class.disable_retries? super end |
#serialize ⇒ Object
51 52 53 |
# File 'lib/batch_processor/batch_job.rb', line 51 def serialize super.merge("batch_id" => batch_id) # rubocop:disable Style/StringHashKeys end |