Merge pull request #8478 from mfo/hs/2130856854/2011688

amelioration(modele_attestation): re-tente a génération de l'attestation dans le cas ou notre objectstorage est en bagotage
This commit is contained in:
mfo 2023-01-23 14:56:40 +01:00 committed by GitHub
commit dcf2b92ef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,22 @@ created_at = @attestation.fetch(:created_at)
logo = @attestation[:logo] logo = @attestation[:logo]
signature = @attestation[:signature] 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| 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_families.update('marianne' => { normal: Rails.root.join('lib/prawn/fonts/marianne/marianne-regular.ttf') })
pdf.font 'marianne' pdf.font 'marianne'