Class: ProjectCacheWorker
- Inherits:
-
Object
- Object
- ProjectCacheWorker
- Includes:
- ApplicationWorker
- Defined in:
- app/workers/project_cache_worker.rb
Overview
Worker for updating any project specific caches.
Constant Summary collapse
- LEASE_TIMEOUT =
15.minutes.to_i
Constants included from ApplicationWorker
ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
Constants included from WorkerAttributes
WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES
Instance Method Summary collapse
-
#perform(project_id, files = [], statistics = [], refresh_statistics = true) ⇒ Object
project_id - The ID of the project for which to flush the cache.
-
#update_statistics(project, statistics = []) ⇒ Object
NOTE: triggering both an immediate update and one in 15 minutes if we successfully obtain the lease.
Methods included from Gitlab::Loggable
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Method Details
#perform(project_id, files = [], statistics = [], refresh_statistics = true) ⇒ Object
project_id - The ID of the project for which to flush the cache. files - An Array containing extra types of files to refresh such as
`:readme` to flush the README and `:changelog` to flush the
CHANGELOG.
statistics - An Array containing columns from ProjectStatistics to
refresh, if empty all columns will be refreshed
refresh_statistics - A boolean that determines whether project statistics should
be updated.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/workers/project_cache_worker.rb', line 26 def perform(project_id, files = [], statistics = [], refresh_statistics = true) project = Project.find_by_id(project_id) return unless project update_statistics(project, statistics) if refresh_statistics return unless project.repository.exists? project.repository.refresh_method_caches(files.map(&:to_sym)) project.cleanup end |
#update_statistics(project, statistics = []) ⇒ Object
NOTE: triggering both an immediate update and one in 15 minutes if we successfully obtain the lease. That way, we only need to wait for the statistics to become accurate if they were already updated once in the last 15 minutes.
44 45 46 47 48 49 50 51 52 |
# File 'app/workers/project_cache_worker.rb', line 44 def update_statistics(project, statistics = []) return if Gitlab::Database.read_only? return unless try_obtain_lease_for(project.id, statistics) Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute lease_key = project_cache_worker_key(project.id, statistics) UpdateProjectStatisticsWorker.perform_in(LEASE_TIMEOUT, lease_key, project.id, statistics) end |