def start_execution(service_id, workflow_name, model_storage, resource_storage, plugin_manager, logger): """ Start an execution for the specified service """ body = request.json executor = DryExecutor( ) if 'executor' in body and body['executor'] == 'dry' else None inputs = body['inputs'] if 'inputs' in body else None task_max_attempts = (body['task_max_attempts'] if 'task_max_attempts' in body else 30) task_retry_interval = (body['task_retry_interval'] if 'task_retry_interval' in body else 30) runner = WorkflowRunner(model_storage, resource_storage, plugin_manager, service_id=service_id, workflow_name=workflow_name, inputs=inputs, executor=executor, task_max_attempts=task_max_attempts, task_retry_interval=task_retry_interval) service = model_storage.service.get(service_id) tname = '{}_{}_{}'.format(service.name, workflow_name, runner.execution_id) thread = threading.ExceptionThread(target=runner.execute, name=tname) thread.start() execution_state[str(runner.execution_id)] = [runner, thread] return jsonify({"id": runner.execution_id}), 202
def resume_execution(execution_id, model_storage, resource_storage, plugin_manager, logger): """ Resume the specified execution """ body = request.json execution = model_storage.execution.get(execution_id) if execution.status != execution.status.CANCELLED: return "cancelled execution cannot be resumed", 400 executor = DryExecutor( ) if 'executor' in body and body['executor'] == 'dry' else None retry_failed_tasks = body['retry_failed_tasks'] \ if 'retry_failed_tasks' in body else False runner = WorkflowRunner(model_storage, resource_storage, plugin_manager, execution_id=execution_id, executor=executor, retry_failed_tasks=retry_failed_tasks) tname = '{}_{}_{}'.format(execution.service.name, execution.workflow_name, runner.execution_id) thread = threading.ExceptionThread(target=runner.execute, name=tname, daemon=True) thread.start() execution_state[str(runner.execution_id)] = [runner, thread] return jsonify({"id": runner.execution_id}), 202
def test_exception_raised_from_thread(): def error_raising_func(): raise ValueError('This is an error') thread = threading.ExceptionThread(target=error_raising_func) thread.start() thread.join() assert thread.is_error() with pytest.raises(ValueError): thread.raise_error_if_exists()