def _process_event(self, event): if self._shutting_down: return event_name = getEventNameByType(event.__class__) stop_event = event_name == "SUPERVISOR_STATE_CHANGE_STOPPING" if stop_event: self._log.info("supervisor stopping!") self._stop() elif event_name.startswith("TICK"): return try: payload_str = text_type(event.payload()) except AttributeError: # old supervisor version payload_str = text_type(event) payload = dict((x.split(":") for x in payload_str.split())) if event_name.startswith("PROCESS_STATE"): pname = "{}:{}".format(payload["groupname"], payload["processname"]) payload[u"process"] = parse_obj(self.getProcessInfo(pname)) # broadcast the event to clients server = self.supervisord.options.identifier new_event = { u"pool": u"multivisor", u"server": text_type(server), u"eventname": text_type(event_name), u"payload": payload, } for channel in self._event_channels: channel.put(new_event) if stop_event: self._shutdown()
def _process_event(self, event): if self._shutting_down: return event_name = getEventNameByType(event.__class__) stop_event = event_name == 'SUPERVISOR_STATE_CHANGE_STOPPING' if stop_event: self._log.info('supervisor stopping!') self._stop() elif event_name.startswith('TICK'): return try: # old supervisor version payload_str = event.payload() except AttributeError: payload_str = str(event) payload = dict((x.split(':') for x in payload_str.split())) if event_name.startswith('PROCESS_STATE'): pname = "{}:{}".format(payload['groupname'], payload['processname']) payload['process'] = self.getProcessInfo(pname) # broadcast the event to clients server = self.supervisord.options.identifier new_event = dict(pool='multivisor', server=server, eventname=event_name, payload=payload) for channel in self._event_channels: channel.put(new_event) if stop_event: self._shutdown()
def on_process(self, event): """ Called when a ProcessEvent is sent by the local Supervisor. The event is published to all Supvisors instances. """ event_name = events.getEventNameByType(event.__class__) self.logger.debug('got Process event from supervisord: {} {}'.format(event_name, event)) # create payload from event payload = {'processname': event.process.config.name, 'groupname': event.process.group.config.name, 'state': ProcessStates._from_string(event_name.split('_')[-1]), 'now': int(time.time()), 'pid': event.process.pid, 'expected': event.expected} self.logger.debug('payload={}'.format(payload)) self.publisher.send_process_event(payload)
def on_process(self, event): """ Called when a ProcessEvent is sent by the local Supervisor. The event is published to all Supvisors instances. """ event_name = events.getEventNameByType(event.__class__) self.logger.debug('got Process event from supervisord: {} {}'.format( event_name, event)) # create payload from event payload = {'name': event.process.config.name, 'group': event.process.group.config.name, 'state': ProcessStates._from_string(event_name.split('_')[-1]), 'now': int(time.time()), 'pid': event.process.pid, 'expected': event.expected} self.logger.debug('payload={}'.format(payload)) self.publisher.send_process_event(payload)
def _eventEnvelope(self, event_type, serial, pool_serial, payload): event_name = events.getEventNameByType(event_type) payload_len = len(payload) D = { 'ver': '3.0', 'sid': self.config.options.identifier, 'serial': serial, 'pool_name': self.config.name, 'pool_serial': pool_serial, 'event_name': event_name, 'len': payload_len, 'payload': payload, } return ('ver:%(ver)s server:%(sid)s serial:%(serial)s ' 'pool:%(pool_name)s poolserial:%(pool_serial)s ' 'eventname:%(event_name)s len:%(len)s\n%(payload)s' % D)
def _eventEnvelope(self, event_type, serial, pool_serial, payload): event_name = events.getEventNameByType(event_type) payload_len = len(payload) D = { 'ver':'3.0', 'sid':self.config.options.identifier, 'serial':serial, 'pool_name':self.config.name, 'pool_serial':pool_serial, 'event_name':event_name, 'len':payload_len, 'payload':payload, } return ('ver:%(ver)s server:%(sid)s serial:%(serial)s ' 'pool:%(pool_name)s poolserial:%(pool_serial)s ' 'eventname:%(event_name)s len:%(len)s\n%(payload)s' % D)
def _handle_event(self, event): if self._server is None: reply = start_rpc_server(self, self._bind) if isinstance(reply, Exception): self._log.critical('severe 0RPC error: %s', reply) self._stop() self._shutdown() return self._server, self._watcher = reply self._channel.put(event) self._watcher.send() # handle stop synchronously event_name = getEventNameByType(event.__class__) if event_name == 'SUPERVISOR_STATE_CHANGE_STOPPING': self._server._stop_event.wait() self._server = None self._watcher = None
def _eventEnvelope(self, event_type, serial, pool_serial, payload): event_name = events.getEventNameByType(event_type) payload_len = len(payload) D = { "ver": "3.0", "sid": self.config.options.identifier, "serial": serial, "pool_name": self.config.name, "pool_serial": pool_serial, "event_name": event_name, "len": payload_len, "payload": payload, } return ( "ver:%(ver)s server:%(sid)s serial:%(serial)s " "pool:%(pool_name)s poolserial:%(pool_serial)s " "eventname:%(event_name)s len:%(len)s\n%(payload)s" % D )
def _process_event(self, event): if self._shutting_down: return event_name = getEventNameByType(event.__class__) if event_name == 'SUPERVISOR_STATE_CHANGE_STOPPING': self._log.warn('noticed that supervisor is dying') self._shutdown() elif event_name.startswith('TICK'): return try: # old supervisor version payload_str = event.payload() except AttributeError: payload_str = str(event) payload = dict((x.split(':') for x in payload_str.split())) if event_name.startswith('PROCESS_STATE'): pname = "{}:{}".format(payload['groupname'], payload['processname']) payload['process'] = self.getProcessInfo(pname) return dict(pool='multivisor', server=self.supervisord.options.identifier, eventname=event_name, payload=payload)
def test_getEventNameByType(self): from supervisor import events for name, value in events.EventTypes.__dict__.items(): self.assertEqual(events.getEventNameByType(value), name)
import json import logging import os import sys import time import xmlrpclib from supervisor import childutils, states from supervisor.events import EventTypes, getEventNameByType from ubuntuone.storage.server.logger import configure_logger PROCESS_COMMUNICATION_STDOUT = \ getEventNameByType(EventTypes.PROCESS_COMMUNICATION_STDOUT) TICK_5 = getEventNameByType(EventTypes.TICK_5) class HeartbeatListener(object): """A supervisor event Listener for PROCESS_COMMUNICATION events. It supports events with a json payload that must have a dict with a 'type' item in order to dispatch to the event handler. """ def __init__(self, timeout, interval, groups, processes, rpc, logger=None, timer=time.time, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr): # there is no __init__ to call in basic.LineReceiver self.logger = logger or logging.getLogger('heartbeat')
import json import logging import os import sys import time import xmlrpclib from supervisor import childutils, states from supervisor.events import EventTypes, getEventNameByType from ubuntuone.storage.server.logger import configure_logger PROCESS_COMMUNICATION_STDOUT = \ getEventNameByType(EventTypes.PROCESS_COMMUNICATION_STDOUT) TICK_5 = getEventNameByType(EventTypes.TICK_5) class HeartbeatListener(object): """A supervisor event Listener for PROCESS_COMMUNICATION events. It supports events with a json payload that must have a dict with a 'type' item in order to dispatch to the event handler. """ def __init__(self, timeout, interval, groups, processes, rpc,