2019-04-01 02:11:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Worker for updating project statistics.
|
2020-02-19 13:09:10 -05:00
|
|
|
class UpdateProjectStatisticsWorker # rubocop:disable Scalability/IdempotentWorker
|
2019-04-01 02:11:08 -04:00
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :source_code_management
|
|
|
|
|
2022-07-26 05:09:02 -04:00
|
|
|
# lease_key - The exclusive lease key to take
|
|
|
|
# project_id - The ID of the project for which to flush the cache.
|
|
|
|
# statistics - An Array containing columns from ProjectStatistics to
|
|
|
|
# refresh, if empty all columns will be refreshed
|
|
|
|
def perform(lease_key, project_id, statistics = [])
|
|
|
|
return unless Gitlab::ExclusiveLease
|
|
|
|
.new(lease_key, timeout: ProjectCacheWorker::LEASE_TIMEOUT)
|
|
|
|
.try_obtain
|
|
|
|
|
2021-11-10 10:13:21 -05:00
|
|
|
project = Project.find_by_id(project_id)
|
2019-04-01 02:11:08 -04:00
|
|
|
|
2019-04-05 09:07:09 -04:00
|
|
|
Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
|
2019-04-01 02:11:08 -04:00
|
|
|
end
|
|
|
|
end
|