Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Reschedule conversion job when direct upload not yet finished

Oliver Günther8e67070af301
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index fb1a3162f1e..8411b575ab1 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -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?
diff --git a/modules/bim/app/models/bim/ifc_models/ifc_model.rb b/modules/bim/app/models/bim/ifc_models/ifc_model.rb
index 801cf04de62..1c39223297d 100644
--- a/modules/bim/app/models/bim/ifc_models/ifc_model.rb
+++ b/modules/bim/app/models/bim/ifc_models/ifc_model.rb
@@ -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
##
diff --git a/modules/bim/app/workers/bim/ifc_models/ifc_conversion_job.rb b/modules/bim/app/workers/bim/ifc_models/ifc_conversion_job.rb
index 1366f79242e..dfacd81f19d 100644
--- a/modules/bim/app/workers/bim/ifc_models/ifc_conversion_job.rb
+++ b/modules/bim/app/workers/bim/ifc_models/ifc_conversion_job.rb
@@ -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
diff --git a/modules/bim/spec/workers/ifc_conversion_job_spec.rb b/modules/bim/spec/workers/ifc_conversion_job_spec.rb
index 547842ac190..460d81c6627 100644
--- a/modules/bim/spec/workers/ifc_conversion_job_spec.rb
+++ b/modules/bim/spec/workers/ifc_conversion_job_spec.rb
@@ -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