Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-10-25 17:01:24 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2016-10-25 17:02:36 +0300
commit3b4af59a5fed342bf7a4718dba6189cdf1d0c017 (patch)
tree01334aa305fe43e442a4ec8d583d55ed02501ca0 /app/workers
parent9a6770388c0e93f98952a40cc88bb7f5ecd23631 (diff)
Don't schedule ProjectCacheWorker unless needed
This changes ProjectCacheWorker.perform_async so it only schedules a job when no lease for the given project is present. This ensures we don't end up scheduling hundreds of jobs when they won't be executed anyway.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/project_cache_worker.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb
index 71b274e0c99..4dfa745fb50 100644
--- a/app/workers/project_cache_worker.rb
+++ b/app/workers/project_cache_worker.rb
@@ -9,6 +9,18 @@ class ProjectCacheWorker
LEASE_TIMEOUT = 15.minutes.to_i
+ def self.lease_for(project_id)
+ Gitlab::ExclusiveLease.
+ new("project_cache_worker:#{project_id}", timeout: LEASE_TIMEOUT)
+ end
+
+ # Overwrite Sidekiq's implementation so we only schedule when actually needed.
+ def self.perform_async(project_id)
+ # If a lease for this project is still being held there's no point in
+ # scheduling a new job.
+ super unless lease_for(project_id).exists?
+ end
+
def perform(project_id)
if try_obtain_lease_for(project_id)
Rails.logger.
@@ -37,8 +49,6 @@ class ProjectCacheWorker
end
def try_obtain_lease_for(project_id)
- Gitlab::ExclusiveLease.
- new("project_cache_worker:#{project_id}", timeout: LEASE_TIMEOUT).
- try_obtain
+ self.class.lease_for(project_id).try_obtain
end
end