def _flush(self): """ feed all cached messages to carbon server """ if not self.skt and not self._connect(): return False buf = '' while not self.cache.empty(): try: c_msg = self.cache.get(block=False) except QEmpty: continue buf += c_msg.pack() SocketHelper.send_bytes_ex(self.skt, buf, self.timeout)
def _flush(self): """ feed all cached messages to carbon server """ if not self.skt and not self._connect(): return False buf = '' while not self.cache.empty(): try: c_msg = self.cache.get(block=False) except QEmpty: continue buf += c_msg.pack() SocketHelper.send_bytes_ex(self.skt, buf, self.timeout)
def feed(self, key, value, timestamp=0, caching=True): """ feed a single message to carbon server @param: caching - True: add to cache, False: send immediately """ if not self.skt and not self._connect(): return False c_msg = CarbonMessage(key, value, timestamp) if caching: if self.cache.full(): self._flush() try: self.cache.put(c_msg, block=False) except QFull: SocketHelper.send_bytes_ex(self.skt, c_msg.pack(), self.timeout) else: SocketHelper.send_bytes_ex(self.skt, c_msg.pack(), self.timeout)
def feed(self, key, value, timestamp=0, caching=True): """ feed a single message to carbon server @param: caching - True: add to cache, False: send immediately """ if not self.skt and not self._connect(): return False c_msg = CarbonMessage(key, value, timestamp) if caching: if self.cache.full(): self._flush() try: self.cache.put(c_msg, block=False) except QFull: SocketHelper.send_bytes_ex(self.skt, c_msg.pack(), self.timeout) else: SocketHelper.send_bytes_ex(self.skt, c_msg.pack(), self.timeout)