1
This commit is contained in:
@@ -6,6 +6,7 @@ import time
|
||||
import json
|
||||
from typing import Dict
|
||||
import re
|
||||
import utils.helpers as helpers
|
||||
|
||||
from utils.redis_client import RedisClient
|
||||
from config.settings import SYNC_CONFIG
|
||||
@@ -69,21 +70,21 @@ class SyncManager:
|
||||
try:
|
||||
|
||||
# 获取所有账号(只获取一次)
|
||||
accounts = await self.get_accounts_from_redis()
|
||||
accounts = self.get_accounts_from_redis()
|
||||
|
||||
if not accounts:
|
||||
logger.warning("未获取到任何账号,等待下次同步")
|
||||
await asyncio.sleep(self.sync_interval)
|
||||
continue
|
||||
|
||||
|
||||
# return
|
||||
self.stats['total_syncs'] += 1
|
||||
sync_start = time.time()
|
||||
|
||||
logger.info(f"第{self.stats['total_syncs']}次同步开始,共 {len(accounts)} 个账号")
|
||||
|
||||
# 执行所有同步器
|
||||
tasks = [syncer.sync(accounts) for syncer in self.syncers]
|
||||
tasks = [syncer.sync_batch(accounts) for syncer in self.syncers]
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
|
||||
@@ -99,6 +100,15 @@ class SyncManager:
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"同步任务异常: {e}")
|
||||
|
||||
# 获取完整的错误信息
|
||||
import traceback
|
||||
error_details = {
|
||||
'error_type': type(e).__name__,
|
||||
'error_message': str(e),
|
||||
'traceback': traceback.format_exc()
|
||||
}
|
||||
logger.error("完整堆栈跟踪:\n{traceback}", traceback=error_details['traceback'])
|
||||
await asyncio.sleep(30)
|
||||
|
||||
def get_accounts_from_redis(self) -> Dict[str, Dict]:
|
||||
@@ -118,7 +128,6 @@ class SyncManager:
|
||||
logger.warning("配置的计算机名未找到数据,尝试自动发现...")
|
||||
accounts_dict = self._discover_all_accounts()
|
||||
|
||||
self.sync_stats['total_accounts'] = len(accounts_dict)
|
||||
logger.info(f"从 {len(self.computer_names)} 个计算机名获取到 {len(accounts_dict)} 个账号")
|
||||
|
||||
return accounts_dict
|
||||
@@ -303,30 +312,17 @@ class SyncManager:
|
||||
"""解析账号信息"""
|
||||
try:
|
||||
source_account_info = json.loads(account_info)
|
||||
|
||||
# print(source_account_info)
|
||||
# 基础信息
|
||||
account_data = {
|
||||
'exchange_id': exchange_id,
|
||||
'k_id': account_id,
|
||||
'st_id': self._safe_int(source_account_info.get('st_id'), 0),
|
||||
'add_time': self._safe_int(source_account_info.get('add_time'), 0),
|
||||
'account_type': source_account_info.get('account_type', 'real'),
|
||||
'st_id': helpers.safe_int(source_account_info.get('st_id'), 0),
|
||||
'add_time': helpers.safe_int(source_account_info.get('add_time'), 0),
|
||||
'api_key': source_account_info.get('api_key', ''),
|
||||
'secret_key': source_account_info.get('secret_key', ''),
|
||||
'password': source_account_info.get('password', ''),
|
||||
'access_token': source_account_info.get('access_token', ''),
|
||||
'remark': source_account_info.get('remark', '')
|
||||
}
|
||||
|
||||
# 合并原始信息
|
||||
result = {**source_account_info, **account_data}
|
||||
|
||||
# 验证必要字段
|
||||
if not result.get('st_id') or not result.get('exchange_id'):
|
||||
logger.warning(f"账号 {account_id} 缺少必要字段: st_id={result.get('st_id')}, exchange_id={result.get('exchange_id')}")
|
||||
return None
|
||||
|
||||
return result
|
||||
return account_data
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"解析账号 {account_id} JSON数据失败: {e}, 原始数据: {account_info[:100]}...")
|
||||
|
||||
Reference in New Issue
Block a user