Module: AngryBatch::Helper

Extended by:
Helper
Included in:
Helper
Defined in:
lib/angry_batch/helper.rb

Instance Method Summary collapse

Instance Method Details

#add_job_to_batch(batch, job) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/angry_batch/helper.rb', line 20

def add_job_to_batch(batch, job)
  job.angry_batch_id = batch.id

  batch.jobs.create!(
    active_job_idx: job.job_id,
    active_job_class: job.class.name,
    active_job_arguments: job.serialize['arguments'],
  )
end

#after_transactionObject



33
34
35
# File 'lib/angry_batch/helper.rb', line 33

def after_transaction(&)
  ActiveRecord.after_all_transactions_commit(&)
end

#assert_batchable(job_class) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/angry_batch/helper.rb', line 12

def assert_batchable(job_class)
  assert_job_class(job_class)

  return if job_class.included_modules.include?(AngryBatch::Batchable)

  raise AngryBatch::BatchArgumentError, "#{job_class} must include AngryBatch::Batchable"
end

#assert_job_class(job_class) ⇒ Object



6
7
8
9
10
# File 'lib/angry_batch/helper.rb', line 6

def assert_job_class(job_class)
  return if job_class.is_a?(Class) && job_class < ActiveJob::Base

  raise AngryBatch::BatchArgumentError, "#{job_class} must be a subclass of ActiveJob::Base"
end