Commit 358a0e88 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'avoid-timeout-in-sidekiq-queue-job-deletion' into 'master'

Avoid using Timeout when deleting Sidekiq jobs

See merge request gitlab-org/gitlab!26392
parents f0bac84d e3b94a6d
......@@ -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
......@@ -31,14 +31,7 @@ describe Gitlab::SidekiqQueue do
context 'when the queue is not processed in time' do
before do
calls = 0
allow(sidekiq_queue).to receive(:job_matches?).and_wrap_original do |m, *args|
raise Timeout::Error if calls > 0
calls += 1
m.call(*args)
end
allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(1, 2, 12)
end
it 'returns a non-completion flag, the number of jobs deleted, and the remaining queue size' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment