summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-10-25 16:26:59 +0000
committerRémy Coutable <remy@rymai.me>2016-10-25 18:31:11 +0200
commit1e4b63b7ead156c852034bb23c6e3dc765f04d8c (patch)
tree4aad86fae263b30ec41c066737132e8abbdfec87 /app
parent5dea12ac22a808261a610ac156c33ef5c09c2bfd (diff)
downloadgitlab-ce-1e4b63b7ead156c852034bb23c6e3dc765f04d8c.tar.gz
Merge branch 'project-cache-worker-scheduling' into 'master'
Don't schedule ProjectCacheWorker unless needed This MR changes `ProjectCacheWorker.perform_async` so scheduling only takes place when needed. See the commits for more details. See merge request !7099 Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app')
-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