Commit 5db0f3f3 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Isolate ProjectCacheWorker specific Geo code in prepended module

parent 4fffe6b7
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
class ProjectCacheWorker class ProjectCacheWorker
include Sidekiq::Worker include Sidekiq::Worker
include DedicatedSidekiqQueue include DedicatedSidekiqQueue
prepend EE::Workers::ProjectCacheWorker
LEASE_TIMEOUT = 15.minutes.to_i LEASE_TIMEOUT = 15.minutes.to_i
...@@ -32,11 +33,7 @@ class ProjectCacheWorker ...@@ -32,11 +33,7 @@ class ProjectCacheWorker
return return
end end
if Gitlab::Geo.secondary? update_caches(project_id)
update_geo_caches(project_id)
else
update_caches(project_id)
end
end end
def update_caches(project_id) def update_caches(project_id)
...@@ -52,18 +49,6 @@ class ProjectCacheWorker ...@@ -52,18 +49,6 @@ class ProjectCacheWorker
end end
end end
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
def update_geo_caches(project_id)
project = Project.find(project_id)
return unless project.repository.exists?
if project.repository.root_ref
project.repository.build_cache
end
end
def try_obtain_lease_for(project_id) def try_obtain_lease_for(project_id)
self.class.lease_for(project_id).try_obtain self.class.lease_for(project_id).try_obtain
end end
......
module EE
module Workers
# Geo specific code for cache re-generation
#
# This module is intended to encapsulate EE-specific methods
# and be **prepended** in the `ProjectCacheWorker` class.
module ProjectCacheWorker
def update_caches(project_id)
if ::Gitlab::Geo.secondary?
update_geo_caches(project_id)
else
super
end
end
private
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
def update_geo_caches(project_id)
project = Project.find(project_id)
return unless project.repository.exists?
if project.repository.root_ref
project.repository.build_cache
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment