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
Added retry_on handling to ManageNextcloudIntegrationJob
Andreas Pfohl45e5cb078810
diff --git a/modules/storages/app/common/storages/errors.rb b/modules/storages/app/common/storages/errors.rbindex 3e1b2cefa93..00d5fb82415 100644--- a/modules/storages/app/common/storages/errors.rb+++ b/modules/storages/app/common/storages/errors.rb@@ -48,6 +48,16 @@ module Storagesendend+ class IntegrationJobError < BaseError+ attr_reader :errors, :storage++ def initialize(storage:, errors:)+ super(errors.log_message)+ @storage = storage+ @errors = errors+ end+ end+def self.registry_error_for(key)case key.split('.')in [storage, 'contracts', model]diff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rbindex 93484254b98..3ae88df231c 100644--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rb+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rb@@ -31,6 +31,16 @@ module Storagesinclude GoodJob::ActiveJobExtensions::Concurrencyusing ::Storages::Peripherals::ServiceResultRefinements+ retry_on ::Storages::Errors::IntegrationJobError, attempts: 5 do |job, errors|+ if job.executions >= 5+ OpenProject::Notifications.send(+ OpenProject::Events::STORAGE_TURNED_UNHEALTHY,+ storage: errors.storage,+ reason: errors.errors.to_s+ )+ end+ end+good_job_control_concurrency_with(total_limit: 2,enqueue_limit: 1,@@ -87,7 +97,7 @@ module Storagesresult.match(on_success: ->(_) { OpenProject::Notifications.send(OpenProject::Events::STORAGE_TURNED_HEALTHY, storage:) },on_failure: ->(errors) do- OpenProject::Notifications.send(OpenProject::Events::STORAGE_TURNED_UNHEALTHY, storage:, reason: errors.to_s)+ raise ::Storages::Errors::IntegrationJobError.new(storage:, errors:)end)enddiff --git a/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rbindex 7e150dbed67..aecea8f61d3 100644--- a/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rb+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rb@@ -134,12 +134,16 @@ RSpec.describe Storages::ManageNextcloudIntegrationJob, :webmock, type: :job dostorage1.reloadend.to(change(storage1, :health_changed_at).to(Time.now.utc)- .and(change(storage1, :health_status).from("pending").to("healthy"))+ .and(change(storage1, :health_status).from("pending").to("healthy")))endendit "marks storage as unhealthy if sync was unsuccessful" do+ job = class_double(Storages::HealthStatusMailerJob)+ allow(Storages::HealthStatusMailerJob).to receive(:set).and_return(job)+ allow(job).to receive(:perform_later)+allow(Storages::NextcloudGroupFolderPropertiesSyncService).to receive(:call).with(storage1)@@ -147,12 +151,42 @@ RSpec.describe Storages::ManageNextcloudIntegrationJob, :webmock, type: :job doTimecop.freeze("2023-03-14T15:17:00Z") doexpect do- subject+ perform_enqueued_jobs { described_class.perform_later }storage1.reloadend.to(change(storage1, :health_changed_at).to(Time.now.utc)- .and(change(storage1, :health_status).from("pending").to("unhealthy"))- .and(change(storage1, :health_reason).from(nil).to("not_found"))+ .and(change(storage1, :health_status).from("pending").to("unhealthy"))+ .and(change(storage1, :health_reason).from(nil).to("not_found"))+ )+ end+ end++ context "when Storages::Errors::IntegrationJobError is raised" do+ before do+ allow(Storages::NextcloudGroupFolderPropertiesSyncService)+ .to receive(:call).with(storage1)+ .and_return(ServiceResult.failure(errors: Storages::StorageError.new(code: :custom_error)))+ end++ it "retries the job" do+ allow(OpenProject::Notifications).to receive(:send)++ perform_enqueued_jobs { described_class.perform_later }++ expect(described_class+ .queue_adapter.performed_jobs+ .last.dig("exception_executions", "[Storages::Errors::IntegrationJobError]")).to eq(5)+ end++ it "sends a notification after the maximum number of attempts" do+ allow(OpenProject::Notifications).to receive(:send)++ perform_enqueued_jobs { described_class.perform_later }++ expect(OpenProject::Notifications).to have_received(:send).with(+ OpenProject::Events::STORAGE_TURNED_UNHEALTHY,+ storage: storage1,+ reason: "custom_error")endend