diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-06 19:05:58 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-06 20:11:59 +0300 |
commit | b33661d6ec8498ae1dadfb3b2be0e4a80e61f108 (patch) | |
tree | d6b80c77965177619a6f4d149a10b613815fbfe6 /spec/workers | |
parent | a291bcdf0d3ed892dcb805e11a43afcadbc20e8b (diff) |
Add ExclusiveLease guards for RepositoryCheck::{DispatchWorker,BatchWorker}
We saw in production that DispatchWorker was running about twice an hour,
which would schedule twice as many jobs as it should.
For some reason, BatchWorker was running 1000 times per hour, possibly
due to Sidekiq RSS kills that caused these jobs to restart.
Adding an ExclusiveLease prevents these jobs from running more
than they should.
Relates to https://gitlab.com/gitlab-com/infrastructure/issues/4526
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/repository_check/batch_worker_spec.rb | 8 | ||||
-rw-r--r-- | spec/workers/repository_check/dispatch_worker_spec.rb | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/spec/workers/repository_check/batch_worker_spec.rb b/spec/workers/repository_check/batch_worker_spec.rb index 6bc551be9ad..ede271b2cdd 100644 --- a/spec/workers/repository_check/batch_worker_spec.rb +++ b/spec/workers/repository_check/batch_worker_spec.rb @@ -62,4 +62,12 @@ describe RepositoryCheck::BatchWorker do expect(subject.perform(shard_name)).to eq([]) end + + it 'does not run if the exclusive lease is taken' do + allow(subject).to receive(:try_obtain_lease).and_return(false) + + expect(subject).not_to receive(:perform_repository_checks) + + subject.perform(shard_name) + end end diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb index 20a4f1f5344..7877429aa8f 100644 --- a/spec/workers/repository_check/dispatch_worker_spec.rb +++ b/spec/workers/repository_check/dispatch_worker_spec.rb @@ -11,6 +11,14 @@ describe RepositoryCheck::DispatchWorker do subject.perform end + it 'does nothing if the exclusive lease is taken' do + allow(subject).to receive(:try_obtain_lease).and_return(false) + + expect(RepositoryCheck::BatchWorker).not_to receive(:perform_async) + + subject.perform + end + it 'dispatches work to RepositoryCheck::BatchWorker' do expect(RepositoryCheck::BatchWorker).to receive(:perform_async).at_least(:once) |