Part of lp.codehosting.codeimport.workermonitor View In Hierarchy
Known subclasses: lp.codehosting.codeimport.tests.test_workermonitor.CIWorkerMonitorProtocolForTesting
In terms of bytes, the protocol is extremely simple: any output is stored in the log file and seen as timeout-resetting activity. Every config.codeimportworker.heartbeat_update_interval seconds we ask the monitor to update the heartbeat of the job we are working on and pass the tail of the log output.
Method | __init__ | Construct an instance. |
Method | connectionMade | See BaseProtocol.connectionMade . |
Method | outReceived | See ProcessProtocol.outReceived . |
Method | processEnded | See ProcessMonitorProtocolWithTimeout.processEnded . |
Method | _updateHeartbeat | Ask the monitor to update the heartbeat. |
Inherited from ProcessMonitorProtocolWithTimeout:
Method | callLater | Override TimeoutMixin.callLater so we use self._clock. |
Method | timeoutConnection | When a timeout occurs, kill the process and record a TimeoutError. |
Inherited from ProcessMonitorProtocol (via ProcessMonitorProtocolWithTimeout):
Method | runNotification | Run a given function in series with other notifications. |
Method | unexpectedError | Something's gone wrong: kill the subprocess and report failure. |
Inherited from ProcessProtocolWithTwoStageKill (via ProcessMonitorProtocolWithTimeout, ProcessMonitorProtocol):
Method | terminateProcess | Terminate the process by SIGINT initially, but SIGKILL if needed. |
Method | _sigkill | Forcefully kill the process. |
Parameters | deferred | See ProcessMonitorProtocol.__init__ -- the deferred
that will be fired when the process has exited. |
worker_monitor | A CodeImportWorkerMonitor instance. | |
log_file | A file object that the output of the child process will be logged to. | |
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. |
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.
We use runNotification() to serialize the updates and ensure that any errors are handled properly. We do not return the deferred, as we want this function to be called at a frequency independent of how long it takes to update the heartbeat.
ProcessProtocol.outReceived
.
Any output resets the timeout, is stored in the logfile and updates the tail of the log.
ProcessMonitorProtocolWithTimeout.processEnded
.
We stop updating the heartbeat when the process exits.