tasks: add progress report to the pjs migration task

Progress is indicated per migrated champ.
This commit is contained in:
Pierre de La Morinerie 2019-05-16 13:37:33 +00:00
parent 21ac60ad04
commit 4cf54e0d28
4 changed files with 88 additions and 21 deletions

View file

@ -14,9 +14,13 @@ class PieceJustificativeToChampPieceJointeMigrationService
procedures_with_pj.where(id: ids_range)
end
def convert_procedure_pjs_to_champ_pjs(procedure)
def number_of_champs_to_migrate(procedure)
(procedure.types_de_piece_justificative.count + 1) * procedure.dossiers.unscope(where: :hidden_at).count
end
def convert_procedure_pjs_to_champ_pjs(procedure, &progress)
types_de_champ_pj = PiecesJustificativesService.types_pj_as_types_de_champ(procedure)
populate_champs_pjs!(procedure, types_de_champ_pj)
populate_champs_pjs!(procedure, types_de_champ_pj, &progress)
# Only destroy the old types PJ once everything has been safely migrated to
# champs PJs. Destroying the types PJ will cascade and destroy the PJs,
@ -29,7 +33,7 @@ class PieceJustificativeToChampPieceJointeMigrationService
@storage_service ||= CarrierwaveActiveStorageMigrationService.new
end
def populate_champs_pjs!(procedure, types_de_champ_pj)
def populate_champs_pjs!(procedure, types_de_champ_pj, &progress)
procedure.types_de_champ += types_de_champ_pj
# Unscope to make sure all dossiers are migrated, even the soft-deleted ones
@ -54,6 +58,8 @@ class PieceJustificativeToChampPieceJointeMigrationService
created_at: dossier.created_at
)
end
yield if block_given?
end
end
rescue