Switching to using 'with db_api.transaction()'

Change-Id: I80eba89e4c748e8c17c3f93f657f844c0e72e8a6
This commit is contained in:
Renat Akhmerov 2014-09-05 14:22:32 +07:00
parent 8c5012a9e2
commit 8a9ae74d8e
2 changed files with 6 additions and 42 deletions

View File

@ -45,9 +45,7 @@ class DefaultEngine(base.Engine):
self._executor_client = executor_client
def start_workflow(self, workflow_name, workflow_input, **params):
db_api.start_tx()
try:
with db_api.transaction():
wf_db = db_api.get_workflow(workflow_name)
wf_spec = spec_parser.get_workflow_spec(wf_db.spec)
@ -67,16 +65,10 @@ class DefaultEngine(base.Engine):
if task_specs:
self._process_task_specs(task_specs, exec_db, wf_handler)
db_api.commit_tx()
finally:
db_api.end_tx()
return exec_db
def on_task_result(self, task_id, raw_result):
db_api.start_tx()
try:
with db_api.transaction():
task_db = db_api.get_task(task_id)
exec_db = db_api.get_execution(task_db.execution_id)
@ -95,32 +87,20 @@ class DefaultEngine(base.Engine):
self._check_subworkflow_completion(exec_db)
db_api.commit_tx()
finally:
db_api.end_tx()
return task_db
def stop_workflow(self, execution_id):
db_api.start_tx()
try:
with db_api.transaction():
exec_db = db_api.get_execution(execution_id)
wf_handler = wfh_factory.create_workflow_handler(exec_db)
wf_handler.stop_workflow()
db_api.commit_tx()
finally:
db_api.end_tx()
return exec_db
def resume_workflow(self, execution_id):
db_api.start_tx()
try:
with db_api.transaction():
exec_db = db_api.get_execution(execution_id)
wf_handler = wfh_factory.create_workflow_handler(exec_db)
@ -131,10 +111,6 @@ class DefaultEngine(base.Engine):
if task_specs:
self._process_task_specs(task_specs, exec_db, wf_handler)
db_api.commit_tx()
finally:
db_api.end_tx()
return exec_db
def rollback_workflow(self, execution_id):

View File

@ -43,34 +43,22 @@ def create_workbook_v2(values):
_add_security_info(values)
_update_specification(values)
db_api_v2.start_tx()
try:
with db_api_v2.transaction():
wb_db = db_api_v2.create_workbook(values)
_check_workbook_definition_update(wb_db, values)
db_api_v2.commit_tx()
finally:
db_api_v2.end_tx()
return wb_db
def update_workbook_v2(workbook_name, values):
_update_specification(values)
db_api_v2.start_tx()
try:
with db_api_v2.transaction():
wb_db = db_api_v2.update_workbook(workbook_name, values)
_check_workbook_definition_update(wb_db, values)
db_api_v2.commit_tx()
finally:
db_api_v2.end_tx()
return wb_db