diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-25 13:05:34 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-25 13:05:34 +0300 |
commit | 895d97af87c66f4763e8d1fc0ef6cae19924b18d (patch) | |
tree | 09a596fb057d11bf94d7c3a323f38049061c6518 /app/workers | |
parent | 0a5a65df0c7d08e3ce041e10906549313a9ad156 (diff) | |
parent | afe90d529c82566886d1f2513dd6bee4fa73ff94 (diff) |
Merge branch 'master' into fix/rename-mwbs-to-merge-when-pipeline-succeeds
* master: (312 commits)
Fix bad selection on dropdown menu for tags filter
Fixed issue boards scrolling with a lot of lists & issues
You can only assign default_branch when editing a project ...
Don't convert data which already is the target type
Stop supporting Google and Azure as backup strategies
renames some of the specs and adds changelog entry
Fixed dragging issue moving wrong issue after multiple drags of issue
Fixed issue boards issue sorting when dragging issue into list
Rephrase some system notes to be compatible with new system note style
Add missing JIRA file that redirects to the new location
Fix documentation to create the `pg_trm` extension before creating the DB
Document that we always use `do...end` for `before` in RSpec
Backport Note#commands_changes from EE
Log mv_namespace parameters
Add default_branch attr to Project API payload in docs.
Fix title case to sentence case
properly escape username validation error message flash
Remove header ids from University docs
Add missing documentation.
Added test that checks the correct select box is there for the LFS ...
...
Conflicts:
app/services/system_note_service.rb
spec/features/merge_requests/merge_when_pipeline_succeeds_spec.rb
spec/services/merge_requests/merge_when_pipeline_succeeds_service_spec.rb
spec/services/system_note_service_spec.rb
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/new_note_worker.rb | 4 | ||||
-rw-r--r-- | app/workers/project_cache_worker.rb | 54 |
2 files changed, 22 insertions, 36 deletions
diff --git a/app/workers/new_note_worker.rb b/app/workers/new_note_worker.rb index 66574d0fd01..926162b8c53 100644 --- a/app/workers/new_note_worker.rb +++ b/app/workers/new_note_worker.rb @@ -2,7 +2,9 @@ class NewNoteWorker include Sidekiq::Worker include DedicatedSidekiqQueue - def perform(note_id) + # Keep extra parameter to preserve backwards compatibility with + # old `NewNoteWorker` jobs (can remove later) + def perform(note_id, _params = {}) if note = Note.find_by(id: note_id) NotificationService.new.new_note(note) Notes::PostProcessService.new(note).execute diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index 4dfa745fb50..27d7e652721 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -1,54 +1,38 @@ # 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 include DedicatedSidekiqQueue LEASE_TIMEOUT = 15.minutes.to_i - def self.lease_for(project_id) - Gitlab::ExclusiveLease. - new("project_cache_worker:#{project_id}", timeout: LEASE_TIMEOUT) - end + # project_id - The ID of the project for which to flush the cache. + # refresh - An Array containing extra types of data to refresh such as + # `:readme` to flush the README and `:changelog` to flush the + # CHANGELOG. + def perform(project_id, refresh = []) + project = Project.find_by(id: project_id) - # 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 + return unless project && project.repository.exists? - 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_repository_size(project) + project.update_commit_count - update_caches(project_id) + project.repository.refresh_method_caches(refresh.map(&:to_sym)) end - def update_caches(project_id) - project = Project.find(project_id) + def update_repository_size(project) + return unless try_obtain_lease_for(project.id, :update_repository_size) - return unless project.repository.exists? + Rails.logger.info("Updating repository size for project #{project.id}") project.update_repository_size - project.update_commit_count - - if project.repository.root_ref - project.repository.build_cache - end end - def try_obtain_lease_for(project_id) - self.class.lease_for(project_id).try_obtain + private + + def try_obtain_lease_for(project_id, section) + Gitlab::ExclusiveLease. + new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT). + try_obtain end end |