def run_workflow_engine_run_command(**kwargs): """Click command used to invoke concrete workflow engine adapters.""" workflow_uuid = kwargs.get("workflow_uuid") workflow_workspace = kwargs.get("workflow_workspace") def _default_exit_handler(signum, frame): """Handle executable exit gracefully.""" if not publisher: raise Exception( "Workflow engine graceful exit requires an instance" "of reana_commons.publisher.WorkflowStatusPublisher") try: logging.warning( "Termination signal {} received. Workflow interrupted ...". format(signum)) publisher.publish_workflow_status( workflow_uuid, 3, logs="Workflow exited unexpectedly.") except Exception: logging.error( "Workflow {} could not be stopped gracefully".format( workflow_uuid), ) try: signal.signal(signal.SIGTERM, exit_handler or _default_exit_handler) publisher = WorkflowStatusPublisher() rjc_api_client = JobControllerAPIClient("reana-job-controller") check_connection_to_job_controller() workflow_engine_run_adapter(publisher, rjc_api_client, **kwargs) logging.info( "Workflow {} finished. Files available at {}.".format( workflow_uuid, workflow_workspace), ) publisher.close() except Exception as e: logging.debug(str(e)) if publisher: publisher.publish_workflow_status( workflow_uuid, 3, logs="Workflow exited unexpectedly.\n{e}".format(e=e), ) else: logging.error( "Workflow {} failed but status " "could not be published causing the workflow to be " "stuck in running status.".format(workflow_uuid), ) finally: if publisher: publisher.close()
from reana_commons.api_client import JobControllerAPIClient from reana_commons.config import (REANA_LOG_LEVEL, REANA_LOG_FORMAT) from reana_commons.publisher import WorkflowStatusPublisher from reana_commons.serial import serial_load from reana_commons.utils import (build_caching_info_message, build_progress_message) from .config import SHARED_VOLUME_PATH from .utils import (build_job_spec, check_cache, copy_workspace_from_cache, copy_workspace_to_cache, escape_shell_arg, load_json, poll_job_status, publish_cache_copy, publish_job_submission, publish_job_success, publish_workflow_failure, publish_workflow_start, sanitize_command) rjc_api_client = JobControllerAPIClient('reana-job-controller') @click.command() @click.option('--workflow-uuid', required=True, help='UUID of workflow to be run.') @click.option('--workflow-workspace', required=True, help='Name of workspace in which workflow should run.') @click.option('--workflow-json', help='JSON representation of workflow object to be run.', callback=load_json) @click.option('--workflow-parameters', help='JSON representation of parameters received by' ' the workflow.',