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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Reschedule conversion job when direct upload not yet finished
Oliver Günther8e67070af301
diff --git a/app/models/attachment.rb b/app/models/attachment.rbindex fb1a3162f1e..8411b575ab1 100644--- a/app/models/attachment.rb+++ b/app/models/attachment.rb@@ -109,6 +109,10 @@ class Attachment < ApplicationRecordendend+ def prepared?+ downloads == -1+ end+# images are sent inlinedef 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.rbindex 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 Bimxkt_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.rbindex 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 todef perform(ifc_model)+ return retry_job(wait: 1.minute) if attachment_missing?(ifc_model)+User.system.run_given doresult = ViewConverterService.new(ifc_model).call@@ -15,6 +17,14 @@ module Bimendendend++ private++ ##+ # Is the ifc attachment of the model ready for consumption?+ def attachment_missing?(ifc_model)+ !ifc_model.ifc_attachment_ready?+ endendendenddiff --git a/modules/bim/spec/workers/ifc_conversion_job_spec.rb b/modules/bim/spec/workers/ifc_conversion_job_spec.rbindex 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 dolet(: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+ endit 'calls the conversion service' doexpect(::Bim::IfcModels::ViewConverterService).to receive_message_chain(:new, :call)- .and_return ServiceResult.new success: true+ .and_return ServiceResult.new success: trueexpect { subject }.not_to raise_errorend++ 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'+ endend