summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorReuben Pereira <rpereira@gitlab.com>2019-04-04 17:27:29 +0000
committerMichael Kozono <mkozono@gmail.com>2019-04-04 17:27:29 +0000
commit5caced3650bf51bd1035347b9823367dd9095e02 (patch)
treee0a1467406fdc7a530d66a0e4fdc07546466238c /app/workers
parenta2d044bf97ec350019b2daebd962ab4901070818 (diff)
downloadgitlab-ce-5caced3650bf51bd1035347b9823367dd9095e02.tar.gz
Allow reactive caching to be used in services
Add support for defining a reactive_cache_worker_finder function that will be used by the reactive_caching_worker to generate/initialize the calling object. This allows reactive caching to work with Services where the object cannot be obtained from DB but a new object can be initialized.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/reactive_caching_worker.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/workers/reactive_caching_worker.rb b/app/workers/reactive_caching_worker.rb
index 9ec8bcca4f3..b30864db802 100644
--- a/app/workers/reactive_caching_worker.rb
+++ b/app/workers/reactive_caching_worker.rb
@@ -3,7 +3,6 @@
class ReactiveCachingWorker
include ApplicationWorker
- # rubocop: disable CodeReuse/ActiveRecord
def perform(class_name, id, *args)
klass = begin
class_name.constantize
@@ -12,7 +11,9 @@ class ReactiveCachingWorker
end
return unless klass
- klass.find_by(klass.primary_key => id).try(:exclusively_update_reactive_cache!, *args)
+ klass
+ .reactive_cache_worker_finder
+ .call(id, *args)
+ .try(:exclusively_update_reactive_cache!, *args)
end
- # rubocop: enable CodeReuse/ActiveRecord
end