summaryrefslogtreecommitdiff
path: root/app/workers/concerns/reactive_cacheable_worker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/concerns/reactive_cacheable_worker.rb')
-rw-r--r--app/workers/concerns/reactive_cacheable_worker.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/workers/concerns/reactive_cacheable_worker.rb b/app/workers/concerns/reactive_cacheable_worker.rb
new file mode 100644
index 00000000000..e73707c2b43
--- /dev/null
+++ b/app/workers/concerns/reactive_cacheable_worker.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module ReactiveCacheableWorker
+ extend ActiveSupport::Concern
+
+ included do
+ include ApplicationWorker
+
+ feature_category_not_owned!
+
+ def self.context_for_arguments(arguments)
+ class_name, *_other_args = arguments
+ Gitlab::ApplicationContext.new(related_class: class_name.to_s)
+ end
+ end
+
+ def perform(class_name, id, *args)
+ klass = begin
+ class_name.constantize
+ rescue NameError
+ nil
+ end
+
+ return unless klass
+
+ klass
+ .reactive_cache_worker_finder
+ .call(id, *args)
+ .try(:exclusively_update_reactive_cache!, *args)
+ rescue ReactiveCaching::ExceededReactiveCacheLimit => e
+ Gitlab::ErrorTracking.track_exception(e)
+ end
+end