Unify admin callback checks and log queue job failures
This commit is contained in:
@@ -2,7 +2,7 @@ import asyncio
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from aiogram import F
|
from aiogram import F
|
||||||
from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
|
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 auth import is_admin_msg
|
||||||
from keyboards import docker_kb, arcane_kb
|
from keyboards import docker_kb, arcane_kb
|
||||||
from services.arcane import list_projects, restart_project, set_project_state, get_project_details
|
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")
|
@dp.callback_query(F.data == "arcane:refresh")
|
||||||
async def arcane_refresh_inline(cb: CallbackQuery):
|
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
|
return
|
||||||
await cb.answer()
|
await cb.answer()
|
||||||
await cmd_arcane_projects(cb.message, edit=True)
|
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:"))
|
@dp.callback_query(F.data.startswith("arcane:page:"))
|
||||||
async def arcane_page(cb: CallbackQuery):
|
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
|
return
|
||||||
try:
|
try:
|
||||||
page = int(cb.data.split(":", 2)[2])
|
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:"))
|
@dp.callback_query(F.data.startswith("arcane:restart:"))
|
||||||
async def arcane_restart(cb: CallbackQuery):
|
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
|
return
|
||||||
|
|
||||||
_, _, pid = cb.data.split(":", 2)
|
_, _, pid = cb.data.split(":", 2)
|
||||||
@@ -160,7 +160,7 @@ async def arcane_restart(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data.startswith("arcane:details:"))
|
@dp.callback_query(F.data.startswith("arcane:details:"))
|
||||||
async def arcane_details(cb: CallbackQuery):
|
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
|
return
|
||||||
|
|
||||||
_, _, pid = cb.data.split(":", 2)
|
_, _, pid = cb.data.split(":", 2)
|
||||||
@@ -208,7 +208,7 @@ async def arcane_details(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data.startswith("arcane:deploy:"))
|
@dp.callback_query(F.data.startswith("arcane:deploy:"))
|
||||||
async def arcane_deploy_status(cb: CallbackQuery):
|
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
|
return
|
||||||
|
|
||||||
_, _, pid = cb.data.split(":", 2)
|
_, _, pid = cb.data.split(":", 2)
|
||||||
@@ -254,7 +254,7 @@ async def arcane_deploy_status(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data.startswith("arcane:up:"))
|
@dp.callback_query(F.data.startswith("arcane:up:"))
|
||||||
async def arcane_up(cb: CallbackQuery):
|
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
|
return
|
||||||
|
|
||||||
_, _, pid = cb.data.split(":", 2)
|
_, _, pid = cb.data.split(":", 2)
|
||||||
@@ -273,7 +273,7 @@ async def arcane_up(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data.startswith("arcane:down:"))
|
@dp.callback_query(F.data.startswith("arcane:down:"))
|
||||||
async def arcane_down(cb: CallbackQuery):
|
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
|
return
|
||||||
|
|
||||||
_, _, pid = cb.data.split(":", 2)
|
_, _, pid = cb.data.split(":", 2)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from aiogram import F
|
from aiogram import F
|
||||||
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton, InputFile, BufferedInputFile
|
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 auth import is_admin_msg
|
||||||
from keyboards import (
|
from keyboards import (
|
||||||
system_info_kb,
|
system_info_kb,
|
||||||
@@ -1022,7 +1022,7 @@ async def updates_page(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data == "upgrade:confirm")
|
@dp.callback_query(F.data == "upgrade:confirm")
|
||||||
async def upgrade_confirm(cb: CallbackQuery):
|
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
|
return
|
||||||
await cb.answer()
|
await cb.answer()
|
||||||
|
|
||||||
@@ -1045,7 +1045,7 @@ async def upgrade_cancel(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data == "reboot:confirm")
|
@dp.callback_query(F.data == "reboot:confirm")
|
||||||
async def reboot_confirm(cb: CallbackQuery):
|
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
|
return
|
||||||
await cb.answer()
|
await cb.answer()
|
||||||
REBOOT_PENDING[cb.from_user.id] = {}
|
REBOOT_PENDING[cb.from_user.id] = {}
|
||||||
@@ -1060,7 +1060,7 @@ async def reboot_cancel(cb: CallbackQuery):
|
|||||||
|
|
||||||
@dp.callback_query(F.data.startswith("npmplus:"))
|
@dp.callback_query(F.data.startswith("npmplus:"))
|
||||||
async def npmplus_toggle(cb: CallbackQuery):
|
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
|
return
|
||||||
parts = cb.data.split(":")
|
parts = cb.data.split(":")
|
||||||
if len(parts) != 3:
|
if len(parts) != 3:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
import time
|
import time
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from typing import Awaitable, Callable, Any
|
from typing import Awaitable, Callable, Any
|
||||||
@@ -25,6 +26,7 @@ _alert_cfg: dict[str, Any] = {
|
|||||||
"last_sent": 0.0,
|
"last_sent": 0.0,
|
||||||
}
|
}
|
||||||
_cfg: dict[str, Any] | None = None
|
_cfg: dict[str, Any] | None = None
|
||||||
|
_logger = logging.getLogger("queue")
|
||||||
|
|
||||||
|
|
||||||
def _save_stats():
|
def _save_stats():
|
||||||
@@ -85,8 +87,18 @@ async def worker():
|
|||||||
status = "ok"
|
status = "ok"
|
||||||
try:
|
try:
|
||||||
await job()
|
await job()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
status = "err"
|
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:
|
finally:
|
||||||
finished_at = time.time()
|
finished_at = time.time()
|
||||||
if _current_meta:
|
if _current_meta:
|
||||||
|
|||||||
Reference in New Issue
Block a user