Skip to content

Commit

Permalink
change_soma_workflow_directory() also isolates the WF controller
Browse files Browse the repository at this point in the history
WF controller may be isolated globally using a class variable, for when
we don't have hands on the way it is constructed.
  • Loading branch information
denisri committed Jun 13, 2024
1 parent a9d1e87 commit c2bf7bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/soma_workflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class WorkflowController(object):

scheduler_config = None

isolated_light_mode = None

def __init__(self,
resource_id=None,
login=None,
Expand Down Expand Up @@ -130,16 +132,21 @@ def __init__(self,
transfers, temporary files...). If the isolated_light_mode
parameter value is True, then generate a temporary directory for
that. Otherwise the parameter should be a directory name which will
be used instead of the default one.
be used instead of the default one. If None, a class-wide variable
WorkflowController.isolated_light_mode is used instread, so you can
set it on the class to allow isolated mode globally.
'''

if isolated_light_mode is None:
isolated_light_mode = WorkflowController.isolated_light_mode
if isolated_light_mode is not None:
if isolated_light_mode is True:
isolated_dir = tempfile.mkdtemp(prefix='soma_workflow_')
else:
isolated_dir = isolated_light_mode
resource_id = 'localhost'
os.environ['SOMA_WORKFLOW_CONFIG'] = osp.join(isolated_dir, 'soma_workflow.cfg')
os.environ['SOMA_WORKFLOW_CONFIG'] = osp.join(isolated_dir,
'soma_workflow.cfg')
db_file = osp.join(isolated_dir, 'soma-workflow.db')
trans_dir = osp.join(isolated_dir, 'transfered_files')
config = configuration.Configuration(
Expand Down
5 changes: 5 additions & 0 deletions python/soma_workflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,9 @@ def change_soma_workflow_directory(directory, config_name=None):
= Configuration.search_config_path
Configuration.search_config_path \
= staticmethod(lambda: six.StringIO(swf_conf))
from .client import WorkflowController
WorkflowController.isolated_light_mode = directory


def restore_soma_workflow_directory():
'''
Expand All @@ -1566,3 +1569,5 @@ def restore_soma_workflow_directory():
else:
Configuration.search_config_path \
= staticmethod(Configuration._old_search_config_path)
from .client import WorkflowController
WorkflowController.isolated_light_mode = None

0 comments on commit c2bf7bc

Please sign in to comment.