Example #1
0
    def _exec_task_process(self, ctxt, task_id, task_type, origin, destination,
                           instance, task_info):
        mp_ctx = multiprocessing.get_context('spawn')
        mp_q = mp_ctx.Queue()
        mp_log_q = mp_ctx.Queue()
        p = mp_ctx.Process(target=_task_process,
                           args=(ctxt, task_id, task_type, origin, destination,
                                 instance, task_info, mp_q, mp_log_q))

        extra_library_paths = self._get_extra_library_paths_for_providers(
            ctxt, task_id, task_type, origin, destination)

        self._start_process_with_custom_library_paths(p, extra_library_paths)
        LOG.info("Task process started: %s", task_id)
        self._rpc_conductor_client.set_task_host(ctxt, task_id, self._server,
                                                 p.pid)

        self._handle_mp_log_events(p, mp_log_q)
        p.join()

        if mp_q.empty():
            raise exception.CoriolisException("Task canceled")
        result = mp_q.get(False)

        if isinstance(result, str):
            raise exception.TaskProcessException(result)
        return result
Example #2
0
    def _exec_task_process(self, ctxt, task_id, task_type, origin, destination,
                           instance, task_info):
        mp_ctx = multiprocessing.get_context('spawn')
        mp_q = mp_ctx.Queue()
        mp_log_q = mp_ctx.Queue()
        p = mp_ctx.Process(target=_task_process,
                           args=(ctxt, task_id, task_type, origin, destination,
                                 instance, task_info, mp_q, mp_log_q))

        extra_library_paths = self._get_extra_library_paths_for_providers(
            ctxt, task_id, task_type, origin, destination)

        self._start_process_with_custom_library_paths(p, extra_library_paths)
        LOG.info("Task process started: %s", task_id)
        try:
            self._rpc_conductor_client.set_task_host(ctxt, task_id,
                                                     self._server, p.pid)
        except (Exception, KeyboardInterrupt) as ex:
            # NOTE: because the task error classes are wrapped,
            # it's easiest to just check that the messages align:
            cancelling_msg = exception.TASK_ALREADY_CANCELLING_EXCEPTION_FMT % {
                "task_id": task_id
            }
            if cancelling_msg in str(ex):
                raise exception.TaskIsCancelling(
                    "Task '%s' was already in cancelling status." % task_id)
            raise

        evt = eventlet.spawn(self._wait_for_process, p, mp_q)
        eventlet.spawn(self._handle_mp_log_events, p, mp_log_q)

        result = evt.wait()
        p.join()

        if result is None:
            raise exception.TaskProcessCanceledException("Task was canceled.")

        if isinstance(result, str):
            raise exception.TaskProcessException(result)
        return result
Example #3
0
    def _exec_task_process(self, ctxt, task_id, task_type, origin, destination,
                           instance, task_info):
        mp_ctx = multiprocessing.get_context('spawn')
        mp_q = mp_ctx.Queue()
        mp_log_q = mp_ctx.Queue()
        p = mp_ctx.Process(target=_task_process,
                           args=(ctxt, task_id, task_type, origin, destination,
                                 instance, task_info, mp_q, mp_log_q))

        extra_library_paths = self._get_extra_library_paths_for_providers(
            ctxt, task_id, task_type, origin, destination)

        try:
            LOG.debug(
                "Attempting to set task host on Conductor for task '%s'.",
                task_id)
            self._rpc_conductor_client.set_task_host(ctxt, task_id,
                                                     self._server)
            LOG.debug("Attempting to start process for task with ID '%s'",
                      task_id)
            self._start_process_with_custom_library_paths(
                p, extra_library_paths)
            LOG.info("Task process started: %s", task_id)
            LOG.debug(
                "Attempting to set task process on Conductor for task '%s'.",
                task_id)
            self._rpc_conductor_client.set_task_process(ctxt, task_id, p.pid)
            LOG.debug(
                "Successfully started and retported task process for task "
                "with ID '%s'.", task_id)
        except (Exception, KeyboardInterrupt) as ex:
            LOG.debug(
                "Exception occurred whilst setting host for task '%s'. Error "
                "was: %s", task_id, utils.get_exception_details())
            # NOTE: because the task error classes are wrapped,
            # it's easiest to just check that the messages align:
            cancelling_msg = exception.TASK_ALREADY_CANCELLING_EXCEPTION_FMT % {
                "task_id": task_id
            }
            if cancelling_msg in str(ex):
                raise exception.TaskIsCancelling(
                    "Task '%s' was already in cancelling status." % task_id)
            raise

        evt = eventlet.spawn(self._wait_for_process, p, mp_q)
        eventlet.spawn(self._handle_mp_log_events, p, mp_log_q)

        result = evt.wait()
        p.join()

        if result is None:
            LOG.debug(
                "No result from process (%s) running task '%s'. "
                "Presuming task was cancelled.", p.pid, task_id)
            raise exception.TaskProcessCanceledException("Task was canceled.")

        if isinstance(result, str):
            LOG.debug(
                "Error message while running task '%s' on process "
                "with PID '%s': %s", task_id, p.pid, result)
            raise exception.TaskProcessException(result)
        return result