def server_heart_beat(self): self.__heart_beat += 1 if self.innerProtocol: if getattr(self.innerProtocol, 'makeTasklet', None): t = self.innerProtocol().makeTasklet(0, None, None) if getattr(t, 'on_server_heart_beat', None): TaskManager.add_task(t.on_server_heart_beat) TaskManager.add_simple_task(Context.Configure.reload)
def receiveDone(self, request): try: tasklet = self.makeTasklet(request) TaskManager.add_task(tasklet.run) TaskManager.schedule() except Exception, e: Logger.exception() body, content_type = http_response_500(self.request) Logger.debug('<====', self.request.path, content_type, repr(body))
def dataReceived(self, data): self._data += data while len(self._data) > 8: cmd, msg_len = struct.unpack('II', self._data[:8]) if msg_len > len(self._data) - 8: return body_data = self._data[8:8 + msg_len] self._data = self._data[8 + msg_len:] try: self.access_ts = Time.current_ts() tasklet = self.makeTasklet(cmd, body_data, self) TaskManager.add_task(tasklet.run, peer=self.peer_key) except Exception, e: Logger.exception(body_data) self.transport.loseConnection()
def connectionLost(self, reason=connectionDone): try: Logger.info('ConnectionLost', 'userId =', self.userId) if self.userId > 0: msg = MsgPack(Message.MSG_INNER_BROKEN) if self.userId in Context.GData.map_client_connect: del Context.GData.map_client_connect[self.userId] msg.set_param('userId', self.userId) if self.gameId > 0: msg.set_param('gameId', self.gameId) tasklet = self.makeTasklet(Message.MSG_INNER_BROKEN, msg, self) TaskManager.add_task(tasklet.run) else: Logger.debug_network('empty user connection lost ... ') except Exception, e: Logger.exception()
def __timeout(self, msg, task, *args, **kwargs): try: TaskManager.add_task(task) except Exception, e: Logger.exception(args)