diff --git a/app/views/administrateurs/attestation_templates/show.pdf.prawn b/app/views/administrateurs/attestation_templates/show.pdf.prawn index da58ab65e..287d7951a 100644 --- a/app/views/administrateurs/attestation_templates/show.pdf.prawn +++ b/app/views/administrateurs/attestation_templates/show.pdf.prawn @@ -31,6 +31,22 @@ created_at = @attestation.fetch(:created_at) logo = @attestation[:logo] signature = @attestation[:signature] +def download_file_and_retry(file_or_attached_one, max_attempts = 3) + if file_or_attached_one.is_a?(ActiveStorage::Attached::One) + file_or_attached_one.download + else + file_or_attached_one.rewind && file_or_attached_one.read + end +rescue Fog::OpenStack::Storage::NotFound => e + if max_attempts > 0 + max_attempts = max_attempts - 1 + sleep 1 + retry + else + raise e + end +end + prawn_document(margin: [top_margin, right_margin, bottom_margin, left_margin], page_size: page_size) do |pdf| pdf.font_families.update('marianne' => { normal: Rails.root.join('lib/prawn/fonts/marianne/marianne-regular.ttf') }) pdf.font 'marianne'