def kill(self): '''关闭''' if hasattr(self.send_let, 'kill'): self.send_let.kill() #将队列中未发送的消息,放入数据库 while not self._queue.empty(): msg = self._queue.get() db.insert('tb_delay_mq', {'msg':str(msg), 'CreateTime':time.time()})
def kill(self): '''关闭''' if hasattr(self.send_let, 'kill'): self.send_let.kill() #将队列中未发送的消息,放入数据库 while not self._queue.empty(): msg = self._queue.get() db.insert('tb_delay_mq', { 'msg': str(msg), 'CreateTime': time.time() })
def getWeekHonour(userid, serverid, timestamp=None): '''获取本周所得的荣誉''' timestamp = timestamp if timestamp else time.time() fields = '*' where = 'UserId=%s AND ServerId=%s' % (userid, serverid) record = db.out_fields(_honour_table, fields, where) if record is None: #没有该用户的记录,插入。 initdata = {'UserId':userid, "ServerId":serverid, 'HonourNum':0, "LastChangeDate":datetime.date.fromtimestamp(timestamp)} db.insert(_honour_table, initdata) return 0 lastchangedate, honornum = record['LastChangeDate'], record['HonourNum'] monday = getMondayDate(timestamp) if lastchangedate >= monday: return honornum return 0
def getWeekHonour(userid, serverid, timestamp=None): '''获取本周所得的荣誉''' timestamp = timestamp if timestamp else time.time() fields = '*' where = 'UserId=%s AND ServerId=%s' % (userid, serverid) record = db.out_fields(_honour_table, fields, where) if record is None: #没有该用户的记录,插入。 initdata = { 'UserId': userid, "ServerId": serverid, 'HonourNum': 0, "LastChangeDate": datetime.date.fromtimestamp(timestamp) } db.insert(_honour_table, initdata) return 0 lastchangedate, honornum = record['LastChangeDate'], record['HonourNum'] monday = getMondayDate(timestamp) if lastchangedate >= monday: return honornum return 0
def loop(self): delay_num = 0 while 1: if delay_num: #如果数据库内有延迟的消息,先发送。 try: delay_mqs = db.out_rows('tb_delay_mq') for delay_mq in delay_mqs: try: msg = self.chk_msg(delay_mq['msg']) except Exception: pass else: self._send(msg) finally: stat = db.execute('tb_delay_mq', 'id=%s' % delay_mq['id']) if not stat: raise TypeError delay_num -= 1 except TypeError: print '数据库出错' except Exception: #发送消息失败 self.conn = None msg = self._queue.get() #发送队列里的消息 try: msg = self.chk_msg(msg) except Exception: #错误的消息 continue try: self._send(msg) except Exception: stat = db.insert('tb_delay_mq', { 'msg': str(msg), 'CreateTime': time.time() }) if not stat: self._queue.put(msg) self.conn = None delay_num += 1
def loop(self): delay_num = 0 while 1: if delay_num: #如果数据库内有延迟的消息,先发送。 try: delay_mqs = db.out_rows('tb_delay_mq') for delay_mq in delay_mqs: try: msg = self.chk_msg(delay_mq['msg']) except Exception: pass else: self._send(msg) finally: stat = db.execute('tb_delay_mq', 'id=%s'%delay_mq['id']) if not stat: raise TypeError delay_num -= 1 except TypeError: print '数据库出错' except Exception: #发送消息失败 self.conn = None msg = self._queue.get() #发送队列里的消息 try: msg = self.chk_msg(msg) except Exception: #错误的消息 continue try: self._send(msg) except Exception: stat = db.insert('tb_delay_mq', {'msg':str(msg), 'CreateTime':time.time()}) if not stat: self._queue.put(msg) self.conn = None delay_num += 1