diff options
Diffstat (limited to 'app/workers/concerns/application_worker.rb')
-rw-r--r-- | app/workers/concerns/application_worker.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/workers/concerns/application_worker.rb b/app/workers/concerns/application_worker.rb index c0062780688..7ab9a0c2a02 100644 --- a/app/workers/concerns/application_worker.rb +++ b/app/workers/concerns/application_worker.rb @@ -11,6 +11,8 @@ module ApplicationWorker include WorkerAttributes include WorkerContext + LOGGING_EXTRA_KEY = 'extra' + included do set_queue @@ -24,6 +26,21 @@ module ApplicationWorker payload.stringify_keys.merge(context) end + + def log_extra_metadata_on_done(key, value) + @done_log_extra_metadata ||= {} + @done_log_extra_metadata[key] = value + end + + def logging_extras + return {} unless @done_log_extra_metadata + + # Prefix keys with class name to avoid conflicts in Elasticsearch types. + # Also prefix with "extra." so that we know to log these new fields. + @done_log_extra_metadata.transform_keys do |k| + "#{LOGGING_EXTRA_KEY}.#{self.class.name.gsub("::", "_").underscore}.#{k}" + end + end end class_methods do |