fixed issues with cancel-execution
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/b0a408f2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/b0a408f2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/b0a408f2 Branch: refs/heads/minor_fixes_to_script_ctx_mechanism Commit: b0a408f2397924e5752e9ef84daf4f1958e0dfb3 Parents: 39634b7 Author: Ran Ziv <[email protected]> Authored: Thu Mar 30 19:30:39 2017 +0300 Committer: Ran Ziv <[email protected]> Committed: Thu Mar 30 19:30:39 2017 +0300 ---------------------------------------------------------------------- aria/cli/commands/executions.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b0a408f2/aria/cli/commands/executions.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py index 74f2e25..d978612 100644 --- a/aria/cli/commands/executions.py +++ b/aria/cli/commands/executions.py @@ -17,12 +17,13 @@ import json import time from .. import utils -from ...utils import formatting from ..table import print_data from ..cli import aria, helptexts from ..exceptions import AriaCliError +from ...modeling.models import Execution from ...storage.exceptions import StorageError from ...orchestrator.workflow_runner import WorkflowRunner +from ...utils import formatting from ...utils import threading EXECUTION_COLUMNS = ['id', 'workflow_name', 'status', 'service_name', @@ -138,29 +139,33 @@ def start(workflow_name, task_max_attempts, task_retry_interval) execution_thread_name = '{0}_{1}'.format(service_name, workflow_name) - execution_thread = threading.ExcThread(target=workflow_runner.execute, - name=execution_thread_name) + execution_thread = threading.ExceptionThread(target=workflow_runner.execute, + name=execution_thread_name) + execution_thread.daemon = True # allows force-cancel to exit immediately logger.info('Starting execution. Press Ctrl+C cancel') + execution_thread.start() try: - execution_thread.start() - execution_thread.join() + while execution_thread.is_alive(): + # using join without a timeout blocks and ignores KeyboardInterrupt + execution_thread.join(1) except KeyboardInterrupt: _cancel_execution(workflow_runner, execution_thread, logger) execution_thread.raise_error_if_exists() - execution = workflow_runner.execution #TODO refresh? + execution = workflow_runner.execution logger.info('Execution has ended with "{0}" status'.format(execution.status)) - #TODO print error if exists + if execution.status == Execution.FAILED: + logger.info('Execution error:\n{0}'.format(execution.error)) def _cancel_execution(workflow_runner, execution_thread, logger): logger.info('Cancelling execution. Press Ctrl+C again to force-cancel') try: workflow_runner.cancel() - execution_thread.join() + while execution_thread.is_alive(): + execution_thread.join(1) except KeyboardInterrupt: - raise NotImplementedError('Force-cancelling functionality is not yet implemented') - # logger.info('Force-cancelling execution') + logger.info('Force-cancelling execution') # TODO handle execution (update status etc.) and exit process
