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:
authorLin Jen-Shin <godfat@godfat.org>2016-10-21 13:20:23 +0300
committerLin Jen-Shin <godfat@godfat.org>2016-10-21 13:20:23 +0300
commit52ed6d8e4ab90b6a467e70aa6ce629e4781a8885 (patch)
treef3bf6f59b38ea69f1c0e3ff2f11fdc82c9db1740 /app/workers
parent6061c9fa3d942c4b1aa466ee8f5f8eb3ae48853e (diff)
parente647af363706d181557e7652cacc19cd7c54dd59 (diff)
Merge remote-tracking branch 'upstream/master' into pipeline-notifications
* upstream/master: (43 commits) Disable warming of the asset cache in Spinach tests under CI Trim project_path whitespace on form submit added skipped definition updated some links in definitions Don't use Hash#slice since it's not supported in Ruby 2.1 Create protected branches bundle [ci skip] Add a comment explaining validate_board_limit callback Fix: Backup restore doesn't clear cache Fix GitLab project import when a user has access only to their default namespace. Test GitLab project import for a user with only their default namespace. We want to release this in 8.13.0 Add CHANGELOG.md entry Return truncation for notification descriptions, fix minor bugs with rendering Use guard clause instead of if-else statement Tests for markdown HipChat notifications Clean up Banzai HTML for HipChat Ensure absolute URLs for single lines from Banzai for HipChat Absolute URLs for Banzai HTML for HipChat Also render commit titles in HipChat notifications Full Banzai rendering for HipChat notifications ...
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/project_cache_worker.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb
index ccefd0f71a0..0d524e88dc3 100644
--- a/app/workers/project_cache_worker.rb
+++ b/app/workers/project_cache_worker.rb
@@ -1,9 +1,30 @@
+# Worker for updating any project specific caches.
+#
+# This worker runs at most once every 15 minutes per project. This is to ensure
+# that multiple instances of jobs for this worker don't hammer the underlying
+# storage engine as much.
class ProjectCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :default
+ LEASE_TIMEOUT = 15.minutes.to_i
+
def perform(project_id)
+ if try_obtain_lease_for(project_id)
+ Rails.logger.
+ info("Obtained ProjectCacheWorker lease for project #{project_id}")
+ else
+ Rails.logger.
+ info("Could not obtain ProjectCacheWorker lease for project #{project_id}")
+
+ return
+ end
+
+ update_caches(project_id)
+ end
+
+ def update_caches(project_id)
project = Project.find(project_id)
return unless project.repository.exists?
@@ -15,4 +36,10 @@ class ProjectCacheWorker
project.repository.build_cache
end
end
+
+ def try_obtain_lease_for(project_id)
+ Gitlab::ExclusiveLease.
+ new("project_cache_worker:#{project_id}", timeout: LEASE_TIMEOUT).
+ try_obtain
+ end
end