diff --git a/handlers/arcane.py b/handlers/arcane.py index daf0a07..b76c484 100644 --- a/handlers/arcane.py +++ b/handlers/arcane.py @@ -2,7 +2,7 @@ import asyncio from datetime import datetime from aiogram import F from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery -from app import dp, cfg +from app import dp, cfg, ADMIN_IDS from auth import is_admin_msg from keyboards import docker_kb, arcane_kb from services.arcane import list_projects, restart_project, set_project_state, get_project_details @@ -115,7 +115,7 @@ async def arcane_refresh(msg: Message): @dp.callback_query(F.data == "arcane:refresh") async def arcane_refresh_inline(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return await cb.answer() await cmd_arcane_projects(cb.message, edit=True) @@ -123,7 +123,7 @@ async def arcane_refresh_inline(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:page:")) async def arcane_page(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return try: page = int(cb.data.split(":", 2)[2]) @@ -141,7 +141,7 @@ async def arcane_page(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:restart:")) async def arcane_restart(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return _, _, pid = cb.data.split(":", 2) @@ -160,7 +160,7 @@ async def arcane_restart(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:details:")) async def arcane_details(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return _, _, pid = cb.data.split(":", 2) @@ -208,7 +208,7 @@ async def arcane_details(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:deploy:")) async def arcane_deploy_status(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return _, _, pid = cb.data.split(":", 2) @@ -254,7 +254,7 @@ async def arcane_deploy_status(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:up:")) async def arcane_up(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return _, _, pid = cb.data.split(":", 2) @@ -273,7 +273,7 @@ async def arcane_up(cb: CallbackQuery): @dp.callback_query(F.data.startswith("arcane:down:")) async def arcane_down(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return _, _, pid = cb.data.split(":", 2) diff --git a/handlers/system.py b/handlers/system.py index 97425c3..6ace571 100644 --- a/handlers/system.py +++ b/handlers/system.py @@ -3,7 +3,7 @@ import os from datetime import datetime, timezone, timedelta from aiogram import F from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton, InputFile, BufferedInputFile -from app import dp, cfg +from app import dp, cfg, ADMIN_IDS from auth import is_admin_msg from keyboards import ( system_info_kb, @@ -1022,7 +1022,7 @@ async def updates_page(cb: CallbackQuery): @dp.callback_query(F.data == "upgrade:confirm") async def upgrade_confirm(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return await cb.answer() @@ -1045,7 +1045,7 @@ async def upgrade_cancel(cb: CallbackQuery): @dp.callback_query(F.data == "reboot:confirm") async def reboot_confirm(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return await cb.answer() REBOOT_PENDING[cb.from_user.id] = {} @@ -1060,7 +1060,7 @@ async def reboot_cancel(cb: CallbackQuery): @dp.callback_query(F.data.startswith("npmplus:")) async def npmplus_toggle(cb: CallbackQuery): - if cb.from_user.id != cfg["telegram"]["admin_id"]: + if cb.from_user.id not in ADMIN_IDS: return parts = cb.data.split(":") if len(parts) != 3: diff --git a/services/queue.py b/services/queue.py index 995d735..e66900e 100644 --- a/services/queue.py +++ b/services/queue.py @@ -1,4 +1,5 @@ import asyncio +import logging import time from collections import deque from typing import Awaitable, Callable, Any @@ -25,6 +26,7 @@ _alert_cfg: dict[str, Any] = { "last_sent": 0.0, } _cfg: dict[str, Any] | None = None +_logger = logging.getLogger("queue") def _save_stats(): @@ -85,8 +87,18 @@ async def worker(): status = "ok" try: await job() - except Exception: + except Exception as e: status = "err" + _logger.exception("Queue job failed: label=%s", label) + if _cfg: + try: + log_incident( + _cfg, + f"queue_job_failed label={label} error={type(e).__name__}: {e}", + category="queue", + ) + except Exception: + pass finally: finished_at = time.time() if _current_meta: