Wrap sync_db operations in transactions
Fix for fail on failed to find system actions Change-Id: Ief7cf96eedd201990ca3c169fb0c1509ee55665e Closes-Bug: 1508379
This commit is contained in:
parent
90934209cb
commit
3b3695efca
@ -42,7 +42,11 @@ def register_standard_actions():
|
||||
|
||||
for action_path in action_paths:
|
||||
action_definition = open(action_path).read()
|
||||
actions.update_actions(action_definition, scope='public')
|
||||
actions.update_actions(
|
||||
action_definition,
|
||||
scope='public',
|
||||
run_in_tx=False
|
||||
)
|
||||
|
||||
|
||||
def get_registered_actions(**kwargs):
|
||||
@ -74,10 +78,10 @@ def _clear_system_action_db():
|
||||
|
||||
|
||||
def sync_db():
|
||||
_clear_system_action_db()
|
||||
|
||||
register_action_classes()
|
||||
register_standard_actions()
|
||||
with db_api.transaction():
|
||||
_clear_system_action_db()
|
||||
register_action_classes()
|
||||
register_standard_actions()
|
||||
|
||||
|
||||
def _register_dynamic_action_classes():
|
||||
@ -106,25 +110,23 @@ def register_action_classes():
|
||||
namespace='mistral.actions',
|
||||
invoke_on_load=False
|
||||
)
|
||||
for name in mgr.names():
|
||||
action_class_str = mgr[name].entry_point_target.replace(':', '.')
|
||||
action_class = mgr[name].plugin
|
||||
description = i_utils.get_docstring(action_class)
|
||||
input_str = i_utils.get_arg_list_as_str(action_class.__init__)
|
||||
|
||||
with db_api.transaction():
|
||||
for name in mgr.names():
|
||||
action_class_str = mgr[name].entry_point_target.replace(':', '.')
|
||||
action_class = mgr[name].plugin
|
||||
description = i_utils.get_docstring(action_class)
|
||||
input_str = i_utils.get_arg_list_as_str(action_class.__init__)
|
||||
attrs = i_utils.get_public_fields(mgr[name].plugin)
|
||||
|
||||
attrs = i_utils.get_public_fields(mgr[name].plugin)
|
||||
register_action_class(
|
||||
name,
|
||||
action_class_str,
|
||||
attrs,
|
||||
description=description,
|
||||
input_str=input_str
|
||||
)
|
||||
|
||||
register_action_class(
|
||||
name,
|
||||
action_class_str,
|
||||
attrs,
|
||||
description=description,
|
||||
input_str=input_str
|
||||
)
|
||||
|
||||
_register_dynamic_action_classes()
|
||||
_register_dynamic_action_classes()
|
||||
|
||||
|
||||
def get_action_db(action_name):
|
||||
|
@ -31,20 +31,39 @@ def create_actions(definition, scope='private'):
|
||||
return db_actions
|
||||
|
||||
|
||||
def update_actions(definition, scope='private'):
|
||||
def update_actions(definition, scope='private', run_in_tx=True):
|
||||
action_list_spec = spec_parser.get_action_list_spec_from_yaml(definition)
|
||||
|
||||
db_actions = []
|
||||
|
||||
with db_api.transaction():
|
||||
for action_spec in action_list_spec.get_actions():
|
||||
db_actions.append(
|
||||
create_or_update_action(
|
||||
action_spec,
|
||||
definition,
|
||||
scope
|
||||
)
|
||||
if run_in_tx:
|
||||
with db_api.transaction():
|
||||
db_actions = _append_all_actions(
|
||||
action_list_spec,
|
||||
db_actions,
|
||||
definition,
|
||||
scope
|
||||
)
|
||||
else:
|
||||
db_actions = _append_all_actions(
|
||||
action_list_spec,
|
||||
db_actions,
|
||||
definition,
|
||||
scope
|
||||
)
|
||||
|
||||
return db_actions
|
||||
|
||||
|
||||
def _append_all_actions(action_list_spec, db_actions, definition, scope):
|
||||
for action_spec in action_list_spec.get_actions():
|
||||
db_actions.append(
|
||||
create_or_update_action(
|
||||
action_spec,
|
||||
definition,
|
||||
scope
|
||||
)
|
||||
)
|
||||
|
||||
return db_actions
|
||||
|
||||
|
@ -21,13 +21,18 @@ from mistral.workbook import parser as spec_parser
|
||||
STD_WF_PATH = 'resources/workflows'
|
||||
|
||||
|
||||
def register_standard_workflows():
|
||||
def register_standard_workflows(run_in_tx=True):
|
||||
workflow_paths = utils.get_file_list(STD_WF_PATH)
|
||||
|
||||
for wf_path in workflow_paths:
|
||||
workflow_definition = open(wf_path).read()
|
||||
|
||||
create_workflows(workflow_definition, scope='public', is_system=True)
|
||||
create_workflows(
|
||||
workflow_definition,
|
||||
scope='public',
|
||||
is_system=True,
|
||||
run_in_tx=run_in_tx
|
||||
)
|
||||
|
||||
|
||||
def _clear_system_workflow_db():
|
||||
@ -35,24 +40,44 @@ def _clear_system_workflow_db():
|
||||
|
||||
|
||||
def sync_db():
|
||||
_clear_system_workflow_db()
|
||||
register_standard_workflows()
|
||||
with db_api.transaction():
|
||||
_clear_system_workflow_db()
|
||||
register_standard_workflows(run_in_tx=False)
|
||||
|
||||
|
||||
def create_workflows(definition, scope='private', is_system=False):
|
||||
def create_workflows(definition, scope='private', is_system=False,
|
||||
run_in_tx=True):
|
||||
wf_list_spec = spec_parser.get_workflow_list_spec_from_yaml(definition)
|
||||
|
||||
db_wfs = []
|
||||
|
||||
with db_api.transaction():
|
||||
for wf_spec in wf_list_spec.get_workflows():
|
||||
db_wfs.append(
|
||||
_create_workflow(wf_spec, definition, scope, is_system)
|
||||
if run_in_tx:
|
||||
with db_api.transaction():
|
||||
_append_all_workflows(
|
||||
definition,
|
||||
is_system,
|
||||
scope,
|
||||
wf_list_spec,
|
||||
db_wfs
|
||||
)
|
||||
else:
|
||||
_append_all_workflows(
|
||||
definition,
|
||||
is_system,
|
||||
scope,
|
||||
wf_list_spec,
|
||||
db_wfs
|
||||
)
|
||||
|
||||
return db_wfs
|
||||
|
||||
|
||||
def _append_all_workflows(definition, is_system, scope, wf_list_spec, db_wfs):
|
||||
for wf_spec in wf_list_spec.get_workflows():
|
||||
db_wfs.append(
|
||||
_create_workflow(wf_spec, definition, scope, is_system)
|
||||
)
|
||||
|
||||
|
||||
def update_workflows(definition, scope='private'):
|
||||
wf_list_spec = spec_parser.get_workflow_list_spec_from_yaml(definition)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user