diff --git a/app/exceptions/exceptions.rb b/app/exceptions/exceptions.rb new file mode 100644 index 00000000..133994f0 --- /dev/null +++ b/app/exceptions/exceptions.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Exceptions + class UploadNotAnalzyed < StandardError; end +end diff --git a/app/jobs/extract_marc_record_metadata_job.rb b/app/jobs/extract_marc_record_metadata_job.rb index abbabfb7..2961f675 100644 --- a/app/jobs/extract_marc_record_metadata_job.rb +++ b/app/jobs/extract_marc_record_metadata_job.rb @@ -5,8 +5,11 @@ # Extract MarcRecord instances from an upload class ExtractMarcRecordMetadataJob < ApplicationJob queue_as :default + retry_on Exceptions::UploadNotAnalzyed, attempts: 10, wait: :exponentially_longer def perform(upload) + raise Exceptions::UploadNotAnalzyed unless upload.analyzed? + upload.with_lock do upload.marc_records.delete_all diff --git a/app/models/upload.rb b/app/models/upload.rb index c1e9f2f2..b69c0b6e 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -16,4 +16,8 @@ class Upload < ApplicationRecord def name super.presence || created_at&.iso8601 end + + def analyzed? + files.all?(&:analyzed?) + end end