Reschedule conversion job when direct upload not yet finished

This commit is contained in:
Oliver Günther
2021-11-04 09:20:42 +01:00
parent 0ec9db6e96
commit 8e67070af3
4 changed files with 56 additions and 2 deletions
+4
View File
@@ -109,6 +109,10 @@ class Attachment < ApplicationRecord
end
end
def prepared?
downloads == -1
end
# images are sent inline
def inlineable?
is_plain_text? || is_image? || is_pdf?
@@ -38,6 +38,13 @@ module Bim
xkt_attachment.present?
end
##
# Test if the ifc attachment is readable.
# Note that it has to access the diskfile and potentially download from storage for that(!)
def ifc_attachment_ready?
!ifc_attachment.prepared? && ifc_attachment.diskfile.present?
end
private
##
@@ -6,6 +6,8 @@ module Bim
##
# Run the conversion of IFC to
def perform(ifc_model)
return retry_job(wait: 1.minute) if attachment_missing?(ifc_model)
User.system.run_given do
result = ViewConverterService.new(ifc_model).call
@@ -15,6 +17,14 @@ module Bim
end
end
end
private
##
# Is the ifc attachment of the model ready for consumption?
def attachment_missing?(ifc_model)
!ifc_model.ifc_attachment_ready?
end
end
end
end
@@ -2,13 +2,46 @@ require 'spec_helper'
describe Bim::IfcModels::IfcConversionJob, type: :job do
let(:model) { FactoryBot.build :ifc_model }
subject { described_class.perform_now(model) }
let(:instance) { described_class.new }
let(:attachment_double) { instance_double(Attachment) }
let(:prepared) { false }
let(:diskfile) { 'foo' }
subject { instance.perform(model) }
before do
allow(model).to receive(:ifc_attachment).and_return(attachment_double)
allow(attachment_double).to receive(:diskfile).and_return diskfile
allow(attachment_double).to receive(:prepared?).and_return prepared
end
it 'calls the conversion service' do
expect(::Bim::IfcModels::ViewConverterService)
.to receive_message_chain(:new, :call)
.and_return ServiceResult.new success: true
.and_return ServiceResult.new success: true
expect { subject }.not_to raise_error
end
shared_examples 'will reschedule' do
it 'will reschedule the job' do
allow(instance).to receive(:retry_job)
subject
expect(instance).to have_received(:retry_job).with(wait: 1.minute)
end
end
context 'when the diskfile is empty' do
let(:diskfile) { nil }
it_behaves_like 'will reschedule'
end
context 'when the attachment is not persisted' do
let(:prepared) { true }
it_behaves_like 'will reschedule'
end
end