From 06bedf6cb4f2b4740691668a7b5cb9e08686cf06 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 29 Apr 2019 09:06:54 -0500 Subject: [PATCH] Pass batch execution kwargs when doing that via subprocess i.e. instead of the normal in-app method --- tailbone/views/batch/core.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index d30c41f4..01adf468 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -28,6 +28,7 @@ from __future__ import unicode_literals, absolute_import import os import sys +import json import datetime import logging import socket @@ -804,7 +805,9 @@ class BatchMasterView(MasterView): thread.start() # launch thread to invoke handler action - thread = Thread(target=self.action_subprocess_thread, args=(batch.uuid, port, username, batch_action, progress)) + thread = Thread(target=self.action_subprocess_thread, + args=(batch.uuid, port, username, batch_action, progress), + kwargs=kwargs) thread.start() else: # either versioning is disabled, or handler doesn't mind @@ -919,7 +922,7 @@ class BatchMasterView(MasterView): log.debug("launching command in subprocess: %s", cmd) subprocess.check_call(cmd) - def action_subprocess_thread(self, batch_uuid, port, username, action, progress): + def action_subprocess_thread(self, batch_uuid, port, username, action, progress, **kwargs): """ This method is sort of an alternative thread target for batch actions, to be used in the event versioning is enabled for the main process but @@ -927,6 +930,18 @@ class BatchMasterView(MasterView): launch a separate process with versioning disabled in order to act on the batch. """ + # figure out the (sub)command args we'll be passing + subargs = [ + '--batch-type', + self.handler.batch_key, + batch_uuid, + ] + if action == 'execute' and kwargs: + subargs.extend([ + '--kwargs', + json.dumps(kwargs), + ]) + # invoke command to act on batch in separate process try: self.launch_subprocess(port=port, username=username, @@ -935,11 +950,7 @@ class BatchMasterView(MasterView): '--no-versioning', ], subcommand='{}-batch'.format(action), - subcommand_args=[ - '--batch-type', - self.handler.batch_key, - batch_uuid, - ]) + subcommand_args=subargs) except Exception as error: log.warning("%s of '%s' batch failed: %s", action, self.handler.batch_key, batch_uuid, exc_info=True)