コード例 #1
0
ファイル: CfgReader.py プロジェクト: fycheung/misc
    def load_cfg(self):
        '''将配置读入字典'''
        for table in self.__class__.tables:
            self.__class__.cfgs[table] = {}
            
            results = db.query('DESC %s' % table)
            if not results:
                continue
            pris = [result['Field'] for result in results if result['Key'] == 'PRI']

            results = db.out_rows(table)
            if not results: #读表失败
                continue
            for result in results:
                row_key = tuple([result[pri] for pri in pris])
                if len(row_key) == 1:
                    row_key = row_key[0]
                self.__class__.cfgs[table][row_key] = result
コード例 #2
0
ファイル: CfgReader.py プロジェクト: hw233/python_misc
    def load_cfg(self):
        '''将配置读入字典'''
        for table in self.__class__.tables:
            self.__class__.cfgs[table] = {}

            results = db.query('DESC %s' % table)
            if not results:
                continue
            pris = [
                result['Field'] for result in results if result['Key'] == 'PRI'
            ]

            results = db.out_rows(table)
            if not results:  #读表失败
                continue
            for result in results:
                row_key = tuple([result[pri] for pri in pris])
                if len(row_key) == 1:
                    row_key = row_key[0]
                self.__class__.cfgs[table][row_key] = result
コード例 #3
0
ファイル: RabbitMod.py プロジェクト: hw233/python_misc
    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
コード例 #4
0
ファイル: RabbitMod.py プロジェクト: fycheung/misc
    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