diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 15:07:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 15:07:52 +0300 |
commit | c6c7437861bff9572747674095c4dfbdfbea4988 (patch) | |
tree | 237d1ed922193f19ae326923457344c082003788 /lib/gitlab/sidekiq_queue.rb | |
parent | d80f3cd75e700b6e62910865bfd36734644ffa89 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/sidekiq_queue.rb')
-rw-r--r-- | lib/gitlab/sidekiq_queue.rb | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/gitlab/sidekiq_queue.rb b/lib/gitlab/sidekiq_queue.rb index 9e9ad3107f3..807c27a71ff 100644 --- a/lib/gitlab/sidekiq_queue.rb +++ b/lib/gitlab/sidekiq_queue.rb @@ -14,7 +14,8 @@ module Gitlab end def drop_jobs!(search_metadata, timeout:) - completed = false + start_time = Gitlab::Metrics::System.monotonic_time + completed = true deleted_jobs = 0 job_search_metadata = @@ -27,18 +28,16 @@ module Gitlab raise NoMetadataError if job_search_metadata.empty? raise InvalidQueueError unless queue - begin - Timeout.timeout(timeout) do - queue.each do |job| - next unless job_matches?(job, job_search_metadata) + queue.each do |job| + if timeout_exceeded?(start_time, timeout) + completed = false + break + end - job.delete - deleted_jobs += 1 - end + next unless job_matches?(job, job_search_metadata) - completed = true - end - rescue Timeout::Error + job.delete + deleted_jobs += 1 end { @@ -48,6 +47,8 @@ module Gitlab } end + private + def queue strong_memoize(:queue) do # Sidekiq::Queue.new always returns a queue, even if it doesn't @@ -59,5 +60,9 @@ module Gitlab def job_matches?(job, job_search_metadata) job_search_metadata.all? { |key, value| job[key] == value } end + + def timeout_exceeded?(start_time, timeout) + (Gitlab::Metrics::System.monotonic_time - start_time) > timeout + end end end |