model: add annotateLogger procedure

This change adds a new procedure to the ChangeQueue to limit
direct access to the event variable member.

Change-Id: Ic48b0a6c67c1ac888cf6d48f0164d4b2e260daec
This commit is contained in:
Tristan Cacqueray 2019-06-07 00:18:49 +00:00
parent e0c975a980
commit d5896f0ac2
2 changed files with 13 additions and 9 deletions

View File

@ -378,7 +378,7 @@ class PipelineManager(object):
change.commit_needs_changes = dependencies
def provisionNodes(self, item):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
jobs = item.findJobsToRequest(item.pipeline.tenant.semaphore_handler)
if not jobs:
return False
@ -618,7 +618,7 @@ class PipelineManager(object):
return self._loadDynamicLayout(item)
def scheduleMerge(self, item, files=None, dirs=None):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
log.debug("Scheduling merge for item %s (files: %s, dirs: %s)" %
(item, files, dirs))
build_set = item.current_build_set
@ -636,7 +636,7 @@ class PipelineManager(object):
return False
def scheduleFilesChanges(self, item):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
log.debug("Scheduling fileschanged for item %s", item)
build_set = item.current_build_set
build_set.files_state = build_set.PENDING
@ -671,7 +671,7 @@ class PipelineManager(object):
return ready
def prepareJobs(self, item):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
# This only runs once the item is in the pipeline's action window
# Returns True if the item is ready, false otherwise
if not item.live:
@ -697,7 +697,7 @@ class PipelineManager(object):
return True
def _processOneItem(self, item, nnfi):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
changed = False
ready = False
dequeued = False

View File

@ -2101,6 +2101,10 @@ class QueueItem(object):
self._cached_sql_results = {}
self.event = event # The trigger event that lead to this queue item
def annotateLogger(self, logger):
"""Return an annotated logger with the trigger event"""
return get_annotated_logger(logger, self.event)
def __repr__(self):
if self.pipeline:
pipeline = self.pipeline.name
@ -3712,7 +3716,7 @@ class Layout(object):
return None
def getProjectPipelineConfig(self, item):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
# Create a project-pipeline config for the given item, taking
# its branch (if any) into consideration. If the project does
# not participate in the pipeline at all (in this branch),
@ -3776,7 +3780,7 @@ class Layout(object):
def _collectJobVariants(self, item, jobname, change, path, jobs, stack,
override_checkouts, indent):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
matched = False
local_override_checkouts = override_checkouts.copy()
override_branch = None
@ -3821,7 +3825,7 @@ class Layout(object):
def collectJobs(self, item, jobname, change, path=None, jobs=None,
stack=None, override_checkouts=None):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
# Stack is the recursion stack of job parent names. Each time
# we go up a level, we add to stack, and it's popped as we
# descend.
@ -3861,7 +3865,7 @@ class Layout(object):
return jobs
def _createJobGraph(self, item, ppc, job_graph, skip_file_matcher):
log = get_annotated_logger(self.log, item.event)
log = item.annotateLogger(self.log)
job_list = ppc.job_list
change = item.change
pipeline = item.pipeline