From e0f2bf1e5c09a4e23415d01b23ccdc7decfdfcbb Mon Sep 17 00:00:00 2001
From: Michele Tartara <mtartara@google.com>
Date: Tue, 26 Mar 2013 09:54:03 +0100
Subject: [PATCH] Add job_id and index to the reason trail

The reason trail will contain an item indicating the job_id and the
index number of the current opcode inside the job queue.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 lib/jqueue.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/jqueue.py b/lib/jqueue.py
index 7ad2ea8ca..110d38685 100644
--- a/lib/jqueue.py
+++ b/lib/jqueue.py
@@ -222,6 +222,22 @@ class _QueuedJob(object):
                "received_timestamp", "start_timestamp", "end_timestamp",
                "__weakref__", "processor_lock", "writable", "archived"]
 
+  def _AddReasons(self):
+    """Extend the reason trail
+
+    Add the reason for all the opcodes of this job to be executed.
+
+    """
+    count = 0
+    for queued_op in self.ops:
+      op = queued_op.input
+      reason_src = opcodes.NameToReasonSrc(op.__class__.__name__)
+      reason_text = "job=%d;index=%d" % (self.id, count)
+      reason = getattr(op, "reason", [])
+      reason.append((reason_src, reason_text, utils.EpochNano()))
+      op.reason = reason
+      count = count + 1
+
   def __init__(self, queue, job_id, ops, writable):
     """Constructor for the _QueuedJob.
 
@@ -242,6 +258,7 @@ class _QueuedJob(object):
     self.queue = queue
     self.id = int(job_id)
     self.ops = [_QueuedOpCode(op) for op in ops]
+    self._AddReasons()
     self.log_serial = 0
     self.received_timestamp = TimeStampNow()
     self.start_timestamp = None
-- 
GitLab