summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-07-24 21:38:53 (GMT)
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-07-24 21:38:53 (GMT)
commitd416fd168c01d5efd27f518f3a43043f4cfeed31 (patch)
tree310375d809b80eeb400d75eade9b3f05a680e566
parent21873953f409ced32f826ca32d1f9c3107b4df83 (diff)
downloadmorph-baserock/pedroalvarez/fix-distbuild-bug.tar.gz
worker_build_scheduler: Consider active jobs when creating/cancellingbaserock/pedroalvarez/fix-distbuild-bug
In WorkerBuildQueuer._handle_request we were only considering running jobs when creating a new one to not create duplicates. This was making `morph distbuild` build some components more than one time. In this commit we also start considering active jobs when cancelling them. Change-Id: Ib0a7296d453ccd0b8c636c7506d9f1da82acc462
-rw-r--r--distbuild/worker_build_scheduler.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/distbuild/worker_build_scheduler.py b/distbuild/worker_build_scheduler.py
index b6042a6..6dc05b2 100644
--- a/distbuild/worker_build_scheduler.py
+++ b/distbuild/worker_build_scheduler.py
@@ -1,6 +1,6 @@
# distbuild/worker_build_scheduler.py -- schedule worker-builds on workers
#
-# Copyright (C) 2012, 2014-2015 Codethink Limited
+# Copyright (C) 2012, 2014-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -118,6 +118,9 @@ class Job(object):
def running(self):
return self._state == 'running'
+ def active(self):
+ return self._state == 'running' or self._state == 'queued'
+
def failed(self):
return self._state == 'failed'
@@ -135,8 +138,8 @@ class JobQueue(object):
self._owner = owner
self._jobs = {}
- def get_running_job_for_artifact(self, artifact_basename):
- jobs = [job for job in self.running_jobs()
+ def get_active_job_for_artifact(self, artifact_basename):
+ jobs = [job for job in self.active_jobs()
if job.artifact.basename() == artifact_basename]
if len(jobs) > 1:
logging.warn('More than one running job for %s',
@@ -185,6 +188,9 @@ class JobQueue(object):
def running_jobs(self):
return [job for job in self if job.running()]
+ def active_jobs(self):
+ return [job for job in self if job.active()]
+
def __repr__(self):
items = []
for job in self._jobs.itervalues():
@@ -297,7 +303,7 @@ class WorkerBuildQueuer(distbuild.StateMachine):
# If so, add our initiator id to the existing job
# If not, create a job
- job = self._jobs.get_running_job_for_artifact(
+ job = self._jobs.get_active_job_for_artifact(
event.artifact.basename())
if job is not None:
job.initiators.append(event.initiator_id)
@@ -476,7 +482,7 @@ class WorkerConnection(distbuild.StateMachine):
event_source)
initiator_id = build_cancel.id
- for job in self._jobs.running_jobs():
+ for job in self._jobs.active_jobs():
self._remove_initiator_from_job(job, initiator_id)
def _remove_initiator_from_job(self, job, initiator_id):