def test_send(self): from supervisor.childutils import listener from supervisor.dispatchers import PEventListenerDispatcher begin = PEventListenerDispatcher.RESULT_TOKEN_START stdout = StringIO() msg = 'the body data ya fool\n' listener.send(msg, stdout) expected = '%s%s\n%s' % (begin, len(msg), msg) self.assertEqual(stdout.getvalue(), expected)
def main(): rpci = getRPCInterface(os.environ) while True: h, p = listener.wait() if not h['eventname'] == 'PROCESS_STATE_EXITED': listener.ok() continue ph, _pd = eventdata(p + '\n') if ph['processname'] == 'mongodb': if int(ph['expected']): listener.ok() continue listener.send("MONGODB HAS BEEN RESTARTED. SO WILL THE APP!") rpci.supervisor.stopProcessGroup('app') rpci.supervisor.startProcessGroup('app', True) listener.ok() now = datetime.now() send_twitter("[FATAL] %s - mongodb has been restarted" % now.isoformat()) return listener.ok()