97731760d7
Dumping too many jobs in the same queue (e.g. the "default" queue) is a dangerous setup. Jobs that take a long time to process can effectively block any other work from being performed given there are enough of these jobs. Furthermore it becomes harder to monitor the jobs as a single queue could contain jobs for different workers. In such a setup the only reliable way of getting counts per job is to iterate over all jobs in a queue, which is a rather time consuming process. By using separate queues for various workers we have better control over throughput, we can add weight to queues, and we can monitor queues better. Some workers still use the same queue whenever their work is related. For example, the various CI pipeline workers use the same "pipeline" queue. This commit includes a Rails migration that moves Sidekiq jobs from the old queues to the new ones. This migration also takes care of doing the inverse if ever needed. This does require downtime as otherwise new jobs could be scheduled in the old queues after this migration completes. This commit also includes an RSpec test that blacklists the use of the "default" queue and ensures cron workers use the "cronjob" queue. Fixes gitlab-org/gitlab-ce#23370
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# 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 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?
|
|
|
|
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)
|
|
Gitlab::ExclusiveLease.
|
|
new("project_cache_worker:#{project_id}", timeout: LEASE_TIMEOUT).
|
|
try_obtain
|
|
end
|
|
end
|