Skip to content

Commit

Permalink
Merge pull request #9582 from demarches-simplifiees/US/fix-export-job
Browse files Browse the repository at this point in the history
correctif(tech.export): il arrive que des exports soient mal identifié (le content-type), ce qui par la suite renvoie des exports vide (0kb)
  • Loading branch information
mfo authored Oct 10, 2023
2 parents 34dcf4a + f4430ce commit ade95f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app/services/archive_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def active_storage_service_local?
end

def upload_with_active_storage
params = blob_default_params(filepath).merge(io: File.open(filepath),
identify: false)
params = blob_default_params(filepath).merge(io: File.open(filepath))
blob = ActiveStorage::Blob.create_and_upload!(**params)
return blob
end
Expand All @@ -64,7 +63,7 @@ def blob_default_params(filepath)
key: namespaced_object_key,
filename: filename,
content_type: 'application/zip',
metadata: { analyzed: true, virus_scan_result: ActiveStorage::VirusScanner::SAFE }
metadata: { analyzed: true, identified: true, virus_scan_result: ActiveStorage::VirusScanner::SAFE }
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/procedure_export_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_blob(io, format)
content_type: content_type(format),
identify: false,
# We generate the exports ourselves, so they are safe
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE, identified: true }
)
end

Expand Down
29 changes: 29 additions & 0 deletions spec/jobs/export_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe ExportJob do
let(:procedure) { create(:procedure, instructeurs: [instructeur]) }
let(:instructeur) { create(:instructeur) }
let(:time_span_type) { :everything }
let(:status) { :tous }
let(:key) { '123' }
let(:export) do
create(:export, format:,
time_span_type:,
key:,
instructeur:,
groupe_instructeurs: procedure.groupe_instructeurs)
end

subject do
ExportJob.perform_now(export)
end
before do
allow_any_instance_of(ArchiveUploader).to receive(:syscall_to_custom_uploader).and_return(true)
end

context 'zip' do
let(:format) { :zip }

it 'does not try to identify file' do
expect { subject }.not_to raise_error(ActiveStorage::FileNotFoundError)
end
end
end

0 comments on commit ade95f5

Please sign in to comment.