review(dossier.reload): evite de recharger le batch qui peut etre confusant

This commit is contained in:
Martin 2022-12-06 10:08:34 +01:00 committed by mfo
parent 7c65af3be0
commit b5f69c8961

View file

@ -68,11 +68,10 @@ class BatchOperation < ApplicationRecord
def track_processed_dossier(success, dossier) def track_processed_dossier(success, dossier)
transaction do transaction do
dossier.update(batch_operation: nil) dossier.update(batch_operation: nil)
reload
manager = Arel::UpdateManager.new.table(arel_table).where(arel_table[:id].eq(id)) manager = Arel::UpdateManager.new.table(arel_table).where(arel_table[:id].eq(id))
values = [] values = []
values.push([arel_table[:run_at], Time.zone.now]) if called_for_first_time? values.push([arel_table[:run_at], Time.zone.now]) if called_for_first_time?
values.push([arel_table[:finished_at], Time.zone.now]) if called_for_last_time? values.push([arel_table[:finished_at], Time.zone.now]) if called_for_last_time?(dossier)
values.push([arel_table[:updated_at], Time.zone.now]) values.push([arel_table[:updated_at], Time.zone.now])
if success if success
values.push([arel_table[:success_dossier_ids], Arel::Nodes::NamedFunction.new('array_append', [arel_table[:success_dossier_ids], dossier.id])]) values.push([arel_table[:success_dossier_ids], Arel::Nodes::NamedFunction.new('array_append', [arel_table[:success_dossier_ids], dossier.id])])
@ -104,8 +103,8 @@ class BatchOperation < ApplicationRecord
end end
# beware, must be reloaded first # beware, must be reloaded first
def called_for_last_time? def called_for_last_time?(dossier_to_ignore)
dossiers.count.zero? dossiers.where.not(id: dossier_to_ignore.id).count.zero?
end end
def total_count def total_count