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
Extract debounce time to be a constant.
Pavel Balashoue495d908e466
diff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rbindex 6ba3427735d..c1f821d1763 100644--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_events_job.rb@@ -27,15 +27,16 @@#++class Storages::ManageNextcloudIntegrationEventsJob < ApplicationJob+ DEBOUNCE_TIME = 20.seconds.freeze+def self.debounce- debounce_time = 20.secondscount = Delayed::Job.where("handler LIKE ?", "%job_class: #{self}%").where(locked_at: nil)- .where('run_at <= ?', debounce_time.from_now)+ .where('run_at <= ?', DEBOUNCE_TIME.from_now).delete_allRails.logger.info("deleted: #{count} jobs")- set(wait: debounce_time).perform_later+ set(wait: DEBOUNCE_TIME).perform_laterenddef performdiff --git a/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rbindex 7e4e30e4a00..d42f26b7a4c 100644--- a/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_events_job_spec.rb@@ -33,12 +33,12 @@ RSpec.describe Storages::ManageNextcloudIntegrationEventsJob, type: :job doit 'debounces job with 1 minute timeframe' doActiveJob::Base.disable_test_adapter- other_handler = ManageNextcloudIntegrationCronJob.perform_later.provider_job_id+ other_handler = Storages::ManageNextcloudIntegrationCronJob.perform_later.provider_job_idsame_handler_within_timeframe1 = described_class.set(wait: 10.seconds).perform_later.provider_job_id- same_handler_within_timeframe2 = described_class.set(wait: 30.seconds).perform_later.provider_job_id- same_handler_within_timeframe3 = described_class.set(wait: 50.seconds).perform_later.provider_job_id- same_handler_out_of_timeframe = described_class.set(wait: 5.minutes).perform_later.provider_job_id- same_handler_within_timeframe_in_progress = described_class.set(wait: 55.seconds).perform_later.tap do |job|+ same_handler_within_timeframe2 = described_class.set(wait: 12.seconds).perform_later.provider_job_id+ same_handler_within_timeframe3 = described_class.set(wait: 16.seconds).perform_later.provider_job_id+ same_handler_out_of_timeframe = described_class.set(wait: 1.minutes).perform_later.provider_job_id+ same_handler_within_timeframe_in_progress = described_class.set(wait: 18.seconds).perform_later.tap do |job|# simulate in progress stateDelayed::Job.where(id: job.provider_job_id).update_all(locked_at: Time.current, locked_by: "test_process #{Process.pid}")end.provider_job_id@@ -48,16 +48,18 @@ RSpec.describe Storages::ManageNextcloudIntegrationEventsJob, type: :job dodescribed_class.debounceexpect(Delayed::Job.count).to eq(4)- expect(Delayed::Job.pluck(:id)).to include(other_handler, same_handler_out_of_timeframe,+ expect(Delayed::Job.pluck(:id)).to include(other_handler,+ same_handler_out_of_timeframe,same_handler_within_timeframe_in_progress)- expect(Delayed::Job.pluck(:id)).not_to include(same_handler_within_timeframe1, same_handler_within_timeframe2,+ expect(Delayed::Job.pluck(:id)).not_to include(same_handler_within_timeframe1,+ same_handler_within_timeframe2,same_handler_within_timeframe3)expect(Delayed::Job.where("handler LIKE ?", "%job_class: #{described_class}%").last.run_at- ).to be_within(3.seconds).of(1.minute.from_now)+ ).to be_within(3.seconds).of(described_class::DEBOUNCE_TIME.from_now)endend