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

Instance Method Details

#batchObject



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

def batch
  return unless batch_job?

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

#batch_job?Boolean

Returns:



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

def batch_job?
  batch_id.present?
end

#deserialize(job_data) ⇒ Object



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

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

#rescue_with_handler(exception) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/batch_processor/batch_job.rb', line 28

def rescue_with_handler(exception)
  batch.job_canceled and return exception if exception.is_a?(BatchAbortedError)

  if batch_job?
    error :batch_job_failed, exception: exception, job_id: job_id
    batch.job_failure
  end

  super
end

#retry_jobObject



39
40
41
42
43
# File 'lib/batch_processor/batch_job.rb', line 39

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

  super
end

#serializeObject



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

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