def handle_result(self, result): process = self.process procname = process.config.name logger = process.config.options.logger try: self.process.group.config.result_handler(process.event, result) logger.debug('%s: event was processed' % procname) self._change_listener_state(EventListenerStates.ACKNOWLEDGED) except RejectEvent: logger.warn('%s: event was rejected' % procname) self._change_listener_state(EventListenerStates.ACKNOWLEDGED) notify(EventRejectedEvent(process, process.event)) except: logger.warn('%s: event caused an error' % procname) self._change_listener_state(EventListenerStates.UNKNOWN) notify(EventRejectedEvent(process, process.event))
def handle_result(self, result): process = self.process procname = process.config.name try: self.process.group.config.result_handler(process.event, result) msg = '%s: BUSY -> ACKNOWLEDGED (processed)' % procname process.listener_state = EventListenerStates.ACKNOWLEDGED except RejectEvent: msg = '%s: BUSY -> ACKNOWLEDGED (rejected)' % procname process.listener_state = EventListenerStates.ACKNOWLEDGED notify(EventRejectedEvent(process, process.event)) except: msg = '%s: BUSY -> UNKNOWN' % procname process.listener_state = EventListenerStates.UNKNOWN notify(EventRejectedEvent(process, process.event)) process.config.options.logger.debug(msg)
def test_EventRejectedEvent_attributes(self): from supervisor.events import EventRejectedEvent options = DummyOptions() pconfig1 = DummyPConfig(options, 'process1', 'process1','/bin/process1') process = DummyProcess(pconfig1) rejected_event = DummyEvent() event = EventRejectedEvent(process, rejected_event) self.assertEqual(event.process, process) self.assertEqual(event.event, rejected_event)
def handle_listener_state_change(self): data = self.state_buffer if not data: return process = self.process procname = process.config.name state = process.listener_state if state == EventListenerStates.UNKNOWN: # this is a fatal state self.state_buffer = '' return if state == EventListenerStates.ACKNOWLEDGED: if len(data) < self.READY_FOR_EVENTS_LEN: # not enough info to make a decision return elif data.startswith(self.READY_FOR_EVENTS_TOKEN): msg = '%s: ACKNOWLEDGED -> READY' % procname process.config.options.logger.debug(msg) process.listener_state = EventListenerStates.READY tokenlen = self.READY_FOR_EVENTS_LEN self.state_buffer = self.state_buffer[tokenlen:] process.event = None else: msg = '%s: ACKNOWLEDGED -> UNKNOWN' % procname process.config.options.logger.debug(msg) process.listener_state = EventListenerStates.UNKNOWN self.state_buffer = '' process.event = None if self.state_buffer: # keep going til its too short self.handle_listener_state_change() else: return elif state == EventListenerStates.READY: # the process sent some spurious data, be a hardass about it msg = '%s: READY -> UNKNOWN' % procname process.config.options.logger.debug(msg) process.listener_state = EventListenerStates.UNKNOWN self.state_buffer = '' process.event = None return elif state == EventListenerStates.BUSY: if self.resultlen is None: # we haven't begun gathering result data yet pos = data.find('\n') if pos == -1: # we can't make a determination yet, we dont have a full # results line return result_line = self.state_buffer[:pos] self.state_buffer = self.state_buffer[pos + 1:] # rid LF resultlen = result_line[self.RESULT_TOKEN_START_LEN:] try: self.resultlen = int(resultlen) except ValueError: msg = ('%s: BUSY -> UNKNOWN (bad result line %r)' % (procname, result_line)) process.config.options.logger.debug(msg) process.listener_state = EventListenerStates.UNKNOWN self.state_buffer = '' notify(EventRejectedEvent(process, process.event)) process.event = None return else: needed = self.resultlen - len(self.result) if needed: self.result += self.state_buffer[:needed] self.state_buffer = self.state_buffer[needed:] needed = self.resultlen - len(self.result) if not needed: self.handle_result(self.result) self.process.event = None self.result = '' self.resultlen = None if self.state_buffer: # keep going til its too short self.handle_listener_state_change() else: return