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

[#51265] Make Nextcloud synchronization more stable.

Pavel Balashou5cf7901b7844
diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rb
index acd2d42025b..53d89af9c98 100644
--- a/modules/storages/app/models/storages/nextcloud_storage.rb
+++ b/modules/storages/app/models/storages/nextcloud_storage.rb
@@ -45,9 +45,14 @@ class Storages::NextcloudStorage < Storages::Storage
timeout_seconds: 0,
transaction: false) do
where("provider_fields->>'automatically_managed' = 'true'")
+ .order(:created_at)
.includes(:oauth_client)
.each do |storage|
Storages::GroupFolderPropertiesSyncService.new(storage).call
+ rescue StandardError => e
+ OpenProject.logger.error(
+ "Unexpected error during NextcloudStorage ##{storage.id} #{storage.host}: #{e.message}"
+ )
end
true
end
diff --git a/modules/storages/spec/models/nextcloud_storage_spec.rb b/modules/storages/spec/models/nextcloud_storage_spec.rb
index 6ac1574162e..9b1059290ae 100644
--- a/modules/storages/spec/models/nextcloud_storage_spec.rb
+++ b/modules/storages/spec/models/nextcloud_storage_spec.rb
@@ -90,6 +90,26 @@ RSpec.describe Storages::NextcloudStorage do
expect(Storages::GroupFolderPropertiesSyncService).to have_received(:new).with(storage1).once
expect(Storages::GroupFolderPropertiesSyncService).not_to have_received(:new).with(storage2)
end
+
+ it 'continues synchronization for other storages if previous one raises an exception' do
+ storage1 = create(:nextcloud_storage, :as_automatically_managed)
+ storage3 = create(:nextcloud_storage, :as_automatically_managed)
+
+ allow(OpenProject.logger).to receive(:error)
+ allow(Storages::GroupFolderPropertiesSyncService).to receive(:new).and_call_original
+ allow(Storages::GroupFolderPropertiesSyncService)
+ .to receive(:new)
+ .with(storage1)
+ .and_raise(RuntimeError.new("Unexpected Error"))
+ allow_any_instance_of(Storages::GroupFolderPropertiesSyncService).to receive(:call).and_return(nil) # rubocop:disable RSpec/AnyInstance
+ expect(subject).to be(true)
+
+ expect(OpenProject.logger).to have_received(:error) do |msg, _|
+ expect(msg).to eq "Unexpected error during NextcloudStorage ##{storage1.id} #{storage1.host}: Unexpected Error"
+ end
+ expect(Storages::GroupFolderPropertiesSyncService).to have_received(:new).with(storage1).once
+ expect(Storages::GroupFolderPropertiesSyncService).to have_received(:new).with(storage3).once
+ end
end
context 'when lock is unfree' do