def processEnded(self, reason): """See `ProcessMonitorProtocolWithTimeout.processEnded`. We stop updating the heartbeat when the process exits. """ ProcessMonitorProtocolWithTimeout.processEnded(self, reason) self._looping_call.stop()
def connectionMade(self): """See `BaseProtocol.connectionMade`. We call updateHeartbeat for the first time when we are connected to the process and every config.codeimportworker.heartbeat_update_interval seconds thereafter. """ ProcessMonitorProtocolWithTimeout.connectionMade(self) self._looping_call.start( config.codeimportworker.heartbeat_update_interval)
def __init__(self, deferred, listener, clock=None): """Construct an instance of the protocol, for listening to a worker. :param deferred: A Deferred that will be fired when the worker has finished (either successfully or unsuccesfully). :param listener: A PullerMaster object that is notified when the protocol receives events from the worker. :param clock: A provider of Twisted's IReactorTime. This parameter exists to allow testing that does not depend on an external clock. If a clock is not passed in explicitly the reactor is used. """ ProcessMonitorProtocolWithTimeout.__init__( self, deferred, config.supermirror.worker_timeout, clock) self.reported_mirror_finished = False self.listener = listener self.wire_protocol = PullerWireProtocol(self) self._stderr = StringIO() self._deferred.addCallbacks(self.checkReportingFinishedAndNoStderr, self.ensureReportingFinished)
def __init__(self, deferred, worker_monitor, log_file, clock=None): """Construct an instance. :param deferred: See `ProcessMonitorProtocol.__init__` -- the deferred that will be fired when the process has exited. :param worker_monitor: A `CodeImportWorkerMonitor` instance. :param log_file: A file object that the output of the child process will be logged to. :param clock: A provider of Twisted's IReactorTime. This parameter exists to allow testing that does not depend on an external clock. If a clock is not passed in explicitly the reactor is used. """ ProcessMonitorProtocolWithTimeout.__init__( self, deferred, clock=clock, timeout=config.codeimport.worker_inactivity_timeout) self.worker_monitor = worker_monitor self._tail = '' self._log_file = log_file self._looping_call = task.LoopingCall(self._updateHeartbeat) self._looping_call.clock = self._clock
def __init__(self, deferred, listener, clock=None): """Construct an instance of the protocol, for listening to a worker. :param deferred: A Deferred that will be fired when the worker has finished (either successfully or unsuccesfully). :param listener: A PullerMaster object that is notified when the protocol receives events from the worker. :param clock: A provider of Twisted's IReactorTime. This parameter exists to allow testing that does not depend on an external clock. If a clock is not passed in explicitly the reactor is used. """ ProcessMonitorProtocolWithTimeout.__init__( self, deferred, config.supermirror.worker_timeout, clock) self.reported_mirror_finished = False self.listener = listener self.wire_protocol = PullerWireProtocol(self) self._stderr = StringIO() self._deferred.addCallbacks( self.checkReportingFinishedAndNoStderr, self.ensureReportingFinished)
def makeProtocol(self): """See `ProcessMonitorProtocolTestsMixin.makeProtocol`.""" return ProcessMonitorProtocolWithTimeout(self.termination_deferred, self.timeout, self.clock)
def makeConnection(self, process): """Called when the process has been created.""" ProcessMonitorProtocolWithTimeout.makeConnection(self, process) NetstringReceiver.makeConnection(self, process) self.wire_protocol.makeConnection(process)