예제 #1
0
                '订单:[{}]支付状态已改变, 添加进队列:[yz_rec]'.format(result['order_sn']),
                'queue', result['pdduid'])
            yz_rec.put(result)
        else:
            result['status'] = 0
            result['is_query'] = 0
            logger.log(
                'DEBUG', '订单:[{}]6分钟内支付状态未改变, 添加进队列:[yz_rec]'.format(
                    result['order_sn']), 'queue', result['pdduid'])
            yz_rec.put(result)


if __name__ == '__main__':
    logger.log('INFO', '检测订单脚本启动...', 'yz_status', 'Admin')
    while True:
        qsize = yz.qsize()
        if qsize == 0:
            time.sleep(3)
            continue
        if qsize < 100:
            pool = Pool(processes=qsize)
        else:
            pool = Pool(processes=100)
        for i in range(qsize):
            try:
                pool.apply_async(yz_main)
            except Exception as ex:
                logger.log('ERROR', '程序异常,异常原因: [{}],重启...'.format(ex),
                           'yz_status', 'Admin')
                time.sleep(10)
                continue
예제 #2
0
                       result['orderno'],
                       result['order_number'], result['pdduid'], result['notifyurl'], result['callbackurl'],
                       result['extends'],
                       result['sign'], result['order_type'], result['pay_url'], result['order_sn'], result['status'],
                       result['is_query'], result['memberid'], result['cookie'], result['is_use'],
                       result['create_time'].strftime('%Y-%m-%d %H:%M:%S'), result['create_time'])
            db_insert(sql)
        # 其它情况下,重新添加队列,查询
        else:
            yz_rec.put(result)


if __name__ == '__main__':
    logger.log('INFO', '检测订单脚本启动...', 'yz_receipt', 'Admin')
    while True:
        qsize = yz_rec.qsize()
        if qsize == 0:
            time.sleep(3)
            continue
        if qsize < 100:
            pool = Pool(processes=qsize)
        else:
            pool = Pool(processes=100)
        for i in range(qsize):
            try:
                pool.apply_async(yz_main)
            except Exception as ex:
                logger.log('ERROR', '程序异常,异常原因: [{}],重启...'.format(ex),
                           'yz_receipt', 'Admin')
                time.sleep(10)
                continue
예제 #3
0
                       result['orderno'],
                       result['order_number'], result['pdduid'], result['notifyurl'], result['callbackurl'],
                       result['extends'],
                       result['sign'], result['order_type'], result['pay_url'], result['order_sn'], result['status'],
                       result['is_query'], result['memberid'], result['passid'], result['is_use'],
                       result['create_time'].strftime('%Y-%m-%d %H:%M:%S'), result['create_time'])
            db_insert(sql)
        # 其它情况下,重新添加队列,查询
        else:
            pdd_rec.put(result)


if __name__ == '__main__':
    logger.log('INFO', '确认收货脚本启动...', 'pdd_receipt', 'Admin')
    while True:
        qsize = pdd_rec.qsize()
        if qsize == 0:
            time.sleep(3)
            continue
        if qsize < 100:
            pool = Pool(processes=qsize)
        else:
            pool = Pool(processes=100)
        for i in range(qsize):
            try:
                pool.apply_async(pdd_main)
            except Exception as ex:
                logger.log('ERROR', '程序异常,异常原因: [{}],重启...'.format(ex), 'pdd_receipt', 'Admin')
                time.sleep(10)
                continue
        pool.close()
예제 #4
0
파일: orm.py 프로젝트: Rondineli/pyg-bench
class MyTaskSet(CountResults):
    def __init__(self, time_execution_in_sec, chart_title, slave, *args,
                 **kwargs):
        super(MyTaskSet, self).__init__(time_execution_in_sec, chart_title,
                                        slave, *args, **kwargs)
        self.running = True
        self.slave = slave
        self.code = None

        self.queue_chart = RedisQueue(name="data_chart",
                                      namespace="data_chart")
        self.queue_tasks = RedisQueue(name="data_tasks",
                                      namespace="data_tasks")
        self.chart = ReportCharts(time_execution_in_sec, chart_title,
                                  self.slave)
        self.db = create_engine(self.config["database"]["db_string"])

    def purge_queues(self):
        self.queue_chart.purge()
        self.queue_tasks.purge()
        self.queue_data.purge()

    def set_tasks(self):
        while self.running:
            self.queue_tasks.put("heartbeat")

    def vacuum(self):
        try:
            self.db.execute("vacuum analyze films;")
            self.db.execute("vacuum films;")

        except InternalError:
            from table import Films
            films = Films()
            films.metadata.create_all(bind=self.db)
        return

    def run(self, thread=0):

        self.chart.update_chart(self.queue_chart, 5, "thread", data=1)
        while self.running and self.queue_tasks.get():
            try:
                self.read()
                self.write()
            except Exception as e:
                self.RESPONSE_TIME_AVERAGE["errors"] += 1

    def read(self):
        self.db.execute("SELECT * FROM films;".format(
            str(uuid.uuid4())[-5:], random.randint(0, self.LIMIT * 100)))

    def write(self):
        # INSERTS
        self.code = str(uuid.uuid4())[-5:]
        self.db.execute(
            "INSERT into films (code, title, did, kind) VALUES('{}', 'test', {}, 't');"
            .format(  # noqa
                self.code, random.randint(0, self.LIMIT * 100)))
        # UPDATES
        new_code = str(uuid.uuid4())[-5:]
        self.db.execute("UPDATE films set code='{}' where code='{}';".format(
            new_code, self.code))

    def on_finish(self):
        self.running = False
        time.sleep(5)
        print("Getting time here to wait all queue get empty")

        while self.queue_data.qsize() > 0 or self.queue_chart.qsize() > 0:
            print("Waiting finishing all pendents query")
            time.sleep(1)

        if not self.slave:
            table = PrettyTable([
                "Item", "Total", "Average Execution (sec)", "Total Errors",
                "Total Executed (sec)"
            ])

            table.add_row([
                "INSERTS", self.RESPONSE_TIME_AVERAGE["count"]["insert"],
                self.RESPONSE_TIME_AVERAGE["average"]["insert"], "", ""
            ])
            table.add_row([
                "UPDATES", self.RESPONSE_TIME_AVERAGE["count"]["update"],
                self.RESPONSE_TIME_AVERAGE["average"]["update"], "", ""
            ])
            table.add_row([
                "SELECTS", self.RESPONSE_TIME_AVERAGE["count"]["select"],
                self.RESPONSE_TIME_AVERAGE["average"]["select"], "", ""
            ])
            table.add_row([
                "", "", "", self.RESPONSE_TIME_AVERAGE["errors"],
                "Finished execution after {} seconds".format(self.TIMING)
            ])

            print(table)

        while self.queue_data.qsize() > 0 or self.queue_chart.qsize() > 0:
            print("Waiting finishing all pendents query")
            time.sleep(1)

        self.purge_queues()

        print("Finished! See http://localhost:9111/ to full report")
        os._exit(0)
예제 #5
0
            break

        result = q.get_nowait()
        if not result:
            timeout += 5
            msg = "超时 " + str(timeout) + " 秒" + " 等待获取..."
            print(msg)
            logging.info(msg)
            time.sleep(5)
            continue
        else:
            sum += 1

            msg = "第 " + str(sum) + " 条 SQL 正在执行: " + str(result)
            print(msg)
            msg = "剩余队列: " + str(q.qsize())
            print(msg)

            cur.execute(result)
except:
    traceback.print_exc()
    logging.error(traceback.format_exc())

end_time = arrow.now().timestamp
use_time = end_time - start_time

msg = "总执行:" + str(sum) + '条  总耗时: ' + str(use_time) + " 开始时间: " + str(
    arrow.get(start_time).format('YYYY-MM-DD HH:mm:ss')) + "  结束时间: " + str(
        arrow.get(end_time).format('YYYY-MM-DD HH:mm:ss'))
print(msg)
logging.info(msg)
예제 #6
0
    else:
        if result['success']:
            logger.log('INFO', '订单:[{}]支付状态已改变, 添加进队列:[pdd_rec]'.format(result['order_sn']), 'queue', result['pdduid'])
            pdd_rec.put(result)
        else:
            result['status'] = 0
            result['is_query'] = 0
            logger.log('DEBUG', '订单:[{}]6分钟内支付状态未改变, 添加进队列:[pdd_rec]'.format(result['order_sn']), 'queue',
                       result['pdduid'])
            pdd_rec.put(result)


if __name__ == '__main__':
    logger.log('INFO', '检测订单脚本启动...', 'pdd_status', 'Admin')
    while True:
        qsize = pdd.qsize()
        if qsize == 0:
            time.sleep(3)
            continue
        if qsize < 100:
            pool = Pool(processes=qsize)
        else:
            pool = Pool(processes=100)
        for i in range(qsize):
            try:
                pool.apply_async(pdd_main)
            except Exception as ex:
                logger.log('ERROR', '程序异常,异常原因: [{}],重启...'.format(ex), 'pdd_status', 'Admin')
                time.sleep(10)
                continue
        pool.close()