feat: automatically clean team and tracker files after 'run all' or 'resume' tasks and notify administrators.
This commit is contained in:
@@ -1293,6 +1293,10 @@ class ProvisionerBot:
|
|||||||
failed_accounts = [r.get("email") for r in (result or []) if r.get("status") != "success"]
|
failed_accounts = [r.get("email") for r in (result or []) if r.get("status") != "success"]
|
||||||
log.info(f"任务完成: {team_name}, 成功: {len(success_accounts)}, 失败: {len(failed_accounts)}")
|
log.info(f"任务完成: {team_name}, 成功: {len(success_accounts)}, 失败: {len(failed_accounts)}")
|
||||||
await self.notifier.notify_task_completed(team_name, success_accounts, failed_accounts)
|
await self.notifier.notify_task_completed(team_name, success_accounts, failed_accounts)
|
||||||
|
|
||||||
|
# run_all / resume 完成后自动清理 team.json
|
||||||
|
if team_name in ("全部", "继续处理"):
|
||||||
|
await self._auto_clean_after_run_all()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"任务异常: {team_name}, 错误: {e}")
|
log.error(f"任务异常: {team_name}, 错误: {e}")
|
||||||
await self.notifier.notify_error(f"任务失败: {team_name}", str(e))
|
await self.notifier.notify_error(f"任务失败: {team_name}", str(e))
|
||||||
@@ -1304,6 +1308,44 @@ class ProvisionerBot:
|
|||||||
# 让标志保持 True,直到下次任务启动时再重置
|
# 让标志保持 True,直到下次任务启动时再重置
|
||||||
# 这样可以确保线程池中的任务能够正确检测到停止信号
|
# 这样可以确保线程池中的任务能够正确检测到停止信号
|
||||||
|
|
||||||
|
async def _auto_clean_after_run_all(self):
|
||||||
|
"""run_all 完成后自动清理 team.json 和 team_tracker.json"""
|
||||||
|
from config import reload_config as _reload
|
||||||
|
try:
|
||||||
|
cleaned = []
|
||||||
|
|
||||||
|
# 清理 team.json
|
||||||
|
if TEAM_JSON_FILE.exists():
|
||||||
|
with open(TEAM_JSON_FILE, "w", encoding="utf-8") as f:
|
||||||
|
f.write("[]")
|
||||||
|
cleaned.append("team.json")
|
||||||
|
|
||||||
|
# 清理 team_tracker.json
|
||||||
|
tracker_file = Path(TEAM_TRACKER_FILE)
|
||||||
|
if tracker_file.exists():
|
||||||
|
with open(tracker_file, "w", encoding="utf-8") as f:
|
||||||
|
f.write('{"teams": {}}')
|
||||||
|
cleaned.append("team_tracker.json")
|
||||||
|
|
||||||
|
# 重载配置
|
||||||
|
_reload()
|
||||||
|
|
||||||
|
if cleaned:
|
||||||
|
log.info(f"自动清理完成: {', '.join(cleaned)}")
|
||||||
|
for chat_id in TELEGRAM_ADMIN_CHAT_IDS:
|
||||||
|
try:
|
||||||
|
await self.app.bot.send_message(
|
||||||
|
chat_id,
|
||||||
|
f"🧹 <b>自动清理完成</b>\n\n"
|
||||||
|
f"已清空: {', '.join(cleaned)}\n\n"
|
||||||
|
f"现在可以导入新的 team.json 了",
|
||||||
|
parse_mode="HTML"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"自动清理失败: {e}")
|
||||||
|
|
||||||
def _run_team_task(self, team_idx: int):
|
def _run_team_task(self, team_idx: int):
|
||||||
"""执行单个 Team 任务 (在线程池中运行)"""
|
"""执行单个 Team 任务 (在线程池中运行)"""
|
||||||
# 延迟导入避免循环依赖
|
# 延迟导入避免循环依赖
|
||||||
|
|||||||
Reference in New Issue
Block a user