32 lines
884 B
Ruby
32 lines
884 B
Ruby
class BatchOperationProcessOneJob < ApplicationJob
|
|
retry_on StandardError, attempts: 1 # default 5, for now no retryable behavior
|
|
|
|
after_perform do |job|
|
|
if called_for_last_time?(job)
|
|
job.arguments.first.touch(:finished_at)
|
|
end
|
|
end
|
|
|
|
def perform(batch_operation, dossier)
|
|
dossier = batch_operation.dossiers_safe_scope.find(dossier.id)
|
|
begin
|
|
ActiveRecord::Base.transaction do
|
|
batch_operation.process_one(dossier)
|
|
batch_operation.track_processed_dossier(true, dossier)
|
|
end
|
|
rescue => error
|
|
ActiveRecord::Base.transaction do
|
|
batch_operation.track_processed_dossier(false, dossier)
|
|
end
|
|
raise error
|
|
end
|
|
rescue ActiveRecord::RecordNotFound
|
|
dossier.update_column(:batch_operation_id, nil)
|
|
end
|
|
|
|
private
|
|
|
|
def called_for_last_time?(job)
|
|
job.arguments.first.dossiers.count.zero?
|
|
end
|
|
end
|