Pass batch execution kwargs when doing that via subprocess
i.e. instead of the normal in-app method
This commit is contained in:
parent
a5f04b6c7f
commit
06bedf6cb4
|
@ -28,6 +28,7 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
@ -804,7 +805,9 @@ class BatchMasterView(MasterView):
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
# launch thread to invoke handler action
|
# 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()
|
thread.start()
|
||||||
|
|
||||||
else: # either versioning is disabled, or handler doesn't mind
|
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)
|
log.debug("launching command in subprocess: %s", cmd)
|
||||||
subprocess.check_call(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,
|
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
|
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
|
launch a separate process with versioning disabled in order to act on
|
||||||
the batch.
|
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
|
# invoke command to act on batch in separate process
|
||||||
try:
|
try:
|
||||||
self.launch_subprocess(port=port, username=username,
|
self.launch_subprocess(port=port, username=username,
|
||||||
|
@ -935,11 +950,7 @@ class BatchMasterView(MasterView):
|
||||||
'--no-versioning',
|
'--no-versioning',
|
||||||
],
|
],
|
||||||
subcommand='{}-batch'.format(action),
|
subcommand='{}-batch'.format(action),
|
||||||
subcommand_args=[
|
subcommand_args=subargs)
|
||||||
'--batch-type',
|
|
||||||
self.handler.batch_key,
|
|
||||||
batch_uuid,
|
|
||||||
])
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
log.warning("%s of '%s' batch failed: %s", action, self.handler.batch_key, batch_uuid, exc_info=True)
|
log.warning("%s of '%s' batch failed: %s", action, self.handler.batch_key, batch_uuid, exc_info=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue