예제 #1
0
 def _log(self, message):
     """
     Log a message from the jobtype itself to the process' log file.
     Useful for debugging jobtypes.
     """
     assert isinstance(self.uuid, UUID)
     logpool.log(self.uuid, "jobtype", message)
예제 #2
0
        def start_processes(_):
            logpool.log(
                self.uuid,
                "internal",
                "Starting work on job %s, assignment of %s tasks."
                % (self.assignment["job"]["title"], len(self.assignment["tasks"])),
            )

            self._before_start()
            logger.debug("%r.start()", self.__class__.__name__)
            try:
                self.start()
                self.start_called = True
                logger.debug("Collecting started deferreds from spawned " "processes")

                if not self.processes:
                    logger.warning("No processes have been started, firing deferreds " "immediately.")
                    self.started_deferred.callback(None)
                    self.stopped_deferred.callback(None)
                else:
                    logger.debug("Making deferred list for %s started " "processes", len(self.processes))
                    processes_deferred = DeferredList([process.started for process in self.processes.values()])
                    processes_deferred.addCallback(lambda x: self.started_deferred.callback(x))
            except Exception as e:
                self.started_deferred.errback(e)
                self.stopped_deferred.errback(e)
예제 #3
0
 def _process_started(self, protocol):
     """
     Called by :meth:`.ProcessProtocol.connectionMade` when a process has
     started running.
     """
     logger.debug("%r._process_started(%r)", self, protocol)
     logpool.log(self.uuid, "internal", "Started %r" % protocol, protocol.pid)
     process_data = self.processes[protocol.uuid]
     process_data.started.callback(protocol)
     if not self.stop_called:
         self.process_started(protocol)
     else:
         self.stop()
예제 #4
0
    def _process_stopped(self, protocol, reason):
        """
        Internal implementation for :meth:`process_stopped`.

        If ``--capture-process-output`` was set when the agent was launched
        all standard output from the process will be sent to the stdout
        of the agent itself.  In all other cases we send the data to the
        logger pool so it can be stored in a file without blocking the
        event loop.
        """
        logger.info("%r stopped (code: %r)", protocol, reason.value.exitCode)
        process_data = self.processes.pop(protocol.uuid)

        try:
            successful = self.is_successful(protocol, reason)
        except Exception as e:
            message = "Exception caught from is_successful(): %r. " "Assuming not successful." % e
            logger.error(message)
            self._log(message)
            successful = False
        if successful:
            logpool.log(
                self.uuid,
                "internal",
                "Process has terminated successfully, code %s" % reason.value.exitCode,
                protocol.pid,
            )
        else:
            self.failed_processes.add((protocol, reason))
            logpool.log(
                self.uuid,
                "internal",
                "Process has not terminated successfully, code %s" % reason.value.exitCode,
                protocol.pid,
            )

        try:
            self.process_stopped(protocol, reason)
        except Exception as e:
            logger.error("Exception caught from process_stopped: %s", e)
        process_data.stopped.callback(reason)

        # If there are no processes running at this point, we assume
        # the assignment is finished
        if len(self.processes) == 0:
            self.stopped_deferred.callback(None)
        return succeed([])