Have a different worker name for each thread.
This makes each thread create their own git repo so threads don't compete and cause race conditions Change-Id: Ifaf1faf153d9b26a0ff302b00603573b04205b04
This commit is contained in:
parent
3b7765de0d
commit
527966b2e4
@ -154,10 +154,11 @@ class FakeWorker(gear.Worker):
|
||||
|
||||
|
||||
class FakeRealDbUpgradeRunner(RealDbUpgradeRunner):
|
||||
def __init__(self, global_config, plugin_config, test):
|
||||
def __init__(self, global_config, plugin_config, worker_name, test):
|
||||
self.test = test
|
||||
super(FakeRealDbUpgradeRunner, self).__init__(global_config,
|
||||
plugin_config)
|
||||
plugin_config,
|
||||
worker_name)
|
||||
|
||||
def setup_gearman(self):
|
||||
self.log.debug("Set up real_db gearman worker")
|
||||
|
@ -36,7 +36,8 @@ class TestGearmanManager(testtools.TestCase):
|
||||
self.config['zuul_server']['gearman_port'] = self.gearman_server.port
|
||||
|
||||
self.task = FakeRealDbUpgradeRunner(self.config,
|
||||
self.config['plugins'][0], self)
|
||||
self.config['plugins'][0],
|
||||
'test-worker-1', self)
|
||||
self.tasks = dict(FakeRealDbUpgradeRunner_worker=self.task)
|
||||
|
||||
self.gearman_manager = FakeGearmanManager(self.config,
|
||||
|
@ -25,7 +25,6 @@ from turbo_hipster.lib import utils
|
||||
import turbo_hipster.task_plugins.gate_real_db_upgrade.handle_results\
|
||||
as handle_results
|
||||
|
||||
__worker_name__ = 'sql-migrate-test-runner-%s' % os.uname()[1]
|
||||
|
||||
# Regex for log checking
|
||||
MIGRATION_START_RE = re.compile('([0-9]+) -> ([0-9]+)\.\.\.$')
|
||||
@ -40,12 +39,14 @@ class Runner(threading.Thread):
|
||||
|
||||
log = logging.getLogger("task_plugins.gate_real_db_upgrade.task.Runner")
|
||||
|
||||
def __init__(self, global_config, plugin_config):
|
||||
def __init__(self, global_config, plugin_config, worker_name):
|
||||
super(Runner, self).__init__()
|
||||
self._stop = threading.Event()
|
||||
self.global_config = global_config
|
||||
self.plugin_config = plugin_config
|
||||
|
||||
self.worker_name = worker_name
|
||||
|
||||
# Set up the runner worker
|
||||
self.gearman_worker = None
|
||||
self.datasets = []
|
||||
@ -64,7 +65,7 @@ class Runner(threading.Thread):
|
||||
|
||||
def setup_gearman(self):
|
||||
self.log.debug("Set up real_db gearman worker")
|
||||
self.gearman_worker = gear.Worker(__worker_name__)
|
||||
self.gearman_worker = gear.Worker(self.worker_name)
|
||||
self.gearman_worker.addServer(
|
||||
self.global_config['zuul_server']['gearman_host'],
|
||||
self.global_config['zuul_server']['gearman_port']
|
||||
@ -314,7 +315,7 @@ class Runner(threading.Thread):
|
||||
project_name + '/.git',
|
||||
os.path.join(
|
||||
self.global_config['git_working_dir'],
|
||||
__worker_name__,
|
||||
self.worker_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
@ -332,7 +333,7 @@ class Runner(threading.Thread):
|
||||
if self.work_data is None:
|
||||
hostname = os.uname()[1]
|
||||
self.work_data = dict(
|
||||
name=__worker_name__,
|
||||
name=self.worker_name,
|
||||
number=self.job.unique,
|
||||
manager='turbo-hipster-manager-%s' % hostname,
|
||||
url='http://localhost',
|
||||
|
@ -76,14 +76,17 @@ class Server(object):
|
||||
|
||||
def run_tasks(self):
|
||||
""" Run the tasks """
|
||||
for plugin in self.plugins:
|
||||
for thread_number, plugin in enumerate(self.plugins):
|
||||
module = plugin['module']
|
||||
self.tasks[module.__worker_name__] = module.Runner(
|
||||
worker_name = '%s-%s-%s' % (plugin['plugin_config']['name'],
|
||||
os.uname()[1], thread_number)
|
||||
self.tasks[worker_name] = module.Runner(
|
||||
self.config,
|
||||
plugin['plugin_config']
|
||||
plugin['plugin_config'],
|
||||
worker_name
|
||||
)
|
||||
self.tasks[module.__worker_name__].daemon = True
|
||||
self.tasks[module.__worker_name__].start()
|
||||
self.tasks[worker_name].daemon = True
|
||||
self.tasks[worker_name].start()
|
||||
|
||||
self.manager = worker_manager.GearmanManager(self.config, self.tasks)
|
||||
self.manager.daemon = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user