Commit 4eb0bb0b authored by ZZH's avatar ZZH

opt sid iccid map 2025-6-9 13:37

parent d139cb85
......@@ -13,6 +13,15 @@ import logging
from pot_libs.aiomqtt_util.hbmqtt_utils import MqttUtil
from pot_libs.mysql_util.mysql_util import MysqlUtil
logging.basicConfig(
filename=f"/home/ubuntu/data/code/log/sid_iccid_map.log",
level=logging.INFO,
format="%(asctime)s - %(filename)s - line:%(lineno)s - %(levelname)s - %(message)s",
)
logging.getLogger('transitions').setLevel(logging.ERROR)
logging.getLogger('transitions.core').setLevel(logging.ERROR)
logger = logging.getLogger()
async def iccid_from_get_status(sid, method="get-status"):
iccid, sim_opt = None, None
......@@ -186,7 +195,7 @@ async def load_iccid(sid):
async def update_all():
sid_iccids, fail_sid, tmp = [], set(), []
sid_total = await load_all_sids()
logging.info(f"start at {pendulum.now()}, sid total:{len(sid_total)}")
logger.info(f"start do task, sid total:{len(sid_total)}")
for i, sid in enumerate(sid_total, start=1):
tmp.append(sid)
if i % 100 and i < len(sid_total):
......@@ -206,30 +215,29 @@ async def update_all():
if sid_iccids:
await batch_insert(sid_iccids)
logging.info(f"finish task, at {pendulum.now()} success:" \
f"{len(sid_iccids)}, fail:{len(fail_sid)}")
# if fail_sid:
# sid_iccids, fail_two, tmp = [], set(), []
# for i, sid in enumerate(list(fail_sid), start=1):
# tmp.append(sid)
# if i % 100 and i < len(fail_sid):
# continue
#
# task_lst = [load_iccid(sid) for sid in tmp]
# for _sid, iccid, sim_opt in await asyncio.gather(*task_lst):
# if iccid:
# sid_iccids.append((_sid, iccid, sim_opt))
# else:
# fail_two.add(_sid)
#
# time.sleep(180)
#
# if sid_iccids:
# await batch_insert(sid_iccids)
#
# print(f"twice, at {pendulum.now()} sucess:{len(sid_iccids)} "
# f"fail:{len(fail_two)}")
logger.info(f"finish, success:{len(sid_iccids)}, fail:{len(fail_sid)}")
if fail_sid:
sid_iccids, fail_two, tmp = [], set(), []
for i, sid in enumerate(list(fail_sid), start=1):
tmp.append(sid)
if i % 100 and i < len(fail_sid):
continue
task_lst = [load_iccid(sid) for sid in tmp]
for _sid, iccid, sim_opt in await asyncio.gather(*task_lst):
if iccid:
sid_iccids.append((_sid, iccid, sim_opt))
else:
fail_two.add(_sid)
time.sleep(180)
if sid_iccids:
await batch_insert(sid_iccids)
logger.info(f"twice finish, sucess:{len(sid_iccids)} "
f"fail:{len(fail_two)}")
async def main2():
......@@ -237,7 +245,7 @@ async def main2():
try:
await update_all()
except Exception as e:
print(f"main2 error:{e}")
logger.exception(f"main2 error:{e}")
time.sleep(1800)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment