From d2ad01f91bf1c38021c7f37b39c864659819414f Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 24 May 2017 17:23:18 -0400 Subject: [PATCH] Add MiqQueue#tracking_label many times we add a task_id for logging only. As we are getting away from task_id, we don't want to loose the logging. This allows us to transition away from task_id The tracking_label will be set in the target system, so a single request can be traced through the various systems --- app/models/miq_queue.rb | 1 + app/models/miq_queue_worker_base/runner.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/models/miq_queue.rb b/app/models/miq_queue.rb index 3b60d3af62c..1f2aca41638 100644 --- a/app/models/miq_queue.rb +++ b/app/models/miq_queue.rb @@ -109,6 +109,7 @@ def self.put(options) options[:queue_name] ||= create_with_options[:queue_name] || "generic" options[:msg_timeout] ||= create_with_options[:msg_timeout] || TIMEOUT options[:task_id] = $_miq_worker_current_msg.try(:task_id) unless options.key?(:task_id) + options[:tracking_label] = Thread.current[:tracking_label] || options[:task_id] unless options.key?(:tracking_label) options[:role] = options[:role].to_s unless options[:role].nil? options[:args] = [options[:args]] if options[:args] && !options[:args].kind_of?(Array) diff --git a/app/models/miq_queue_worker_base/runner.rb b/app/models/miq_queue_worker_base/runner.rb index f4a1d73b67b..363536bacb7 100644 --- a/app/models/miq_queue_worker_base/runner.rb +++ b/app/models/miq_queue_worker_base/runner.rb @@ -104,6 +104,7 @@ def deliver_queue_message(msg) begin $_miq_worker_current_msg = msg + Thread.current[:tracking_label] = msg.tracking_label || msg.task_id status, message, result = msg.deliver if status == MiqQueue::STATUS_TIMEOUT @@ -122,6 +123,7 @@ def deliver_queue_message(msg) msg.unget ensure $_miq_worker_current_msg = nil # to avoid log messages inadvertantly prefixed by previous task_id + Thread.current[:tracking_label] = nil # # This tells the broker to release any memory being held on behalf of this process # and reset the global broker handle ($vim_broker_client).