2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-19 06:03:59 +01:00
|
|
|
class BatchOperationProcessOneJob < ApplicationJob
|
2024-09-24 11:24:02 +02:00
|
|
|
queue_as :mailers # hotfix
|
2022-12-22 14:22:09 +01:00
|
|
|
retry_on StandardError, attempts: 1 # default 5, for now no retryable behavior
|
2022-11-25 15:43:00 +01:00
|
|
|
|
2022-11-18 16:59:46 +01:00
|
|
|
def perform(batch_operation, dossier)
|
2022-11-25 15:43:00 +01:00
|
|
|
dossier = batch_operation.dossiers_safe_scope.find(dossier.id)
|
2022-11-18 16:59:46 +01:00
|
|
|
begin
|
2022-12-22 14:22:09 +01:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
batch_operation.process_one(dossier)
|
|
|
|
batch_operation.track_processed_dossier(true, dossier)
|
|
|
|
end
|
2022-11-18 16:59:46 +01:00
|
|
|
rescue => error
|
2022-12-22 14:22:09 +01:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
batch_operation.track_processed_dossier(false, dossier)
|
|
|
|
end
|
2022-11-18 16:59:46 +01:00
|
|
|
raise error
|
|
|
|
end
|
2022-11-25 15:43:00 +01:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2022-12-22 14:22:09 +01:00
|
|
|
dossier.update_column(:batch_operation_id, nil)
|
2022-11-18 16:59:46 +01:00
|
|
|
end
|
|
|
|
end
|