feat(agent-office): youtube_publisher 파이프라인 실패 텔레그램 알림+재시도 버튼

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-12 00:36:38 +09:00
parent d048251a97
commit 084e4f1b4d
3 changed files with 215 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ class YoutubePublisherAgent(BaseAgent):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._notified_state_per_pipeline: dict[int, tuple] = {}
self._notified_failed: set[int] = set()
async def poll_state_changes(self) -> None:
"""주기적으로 호출되어 *_pending 신규 진입 시 텔레그램 발송."""
@@ -48,6 +49,32 @@ class YoutubePublisherAgent(BaseAgent):
await self._notify_step(p)
self._notified_state_per_pipeline[pid] = key
try:
failed = await service_proxy.list_failed_pipelines()
except Exception as e:
logger.warning("failed 폴링 실패: %s", e)
failed = []
for p in failed:
pid = p.get("id")
if pid is None:
continue
if pid not in self._notified_failed:
await self._notify_failed(p)
self._notified_failed.add(pid)
# 재개되어 failed에서 벗어난 파이프라인은 재알림 가능하도록 해제
failed_ids = {p.get("id") for p in failed}
self._notified_failed &= failed_ids
async def _notify_failed(self, p: dict) -> None:
reason = p.get("failed_reason") or "?"
step = reason.split(":", 1)[0].strip()
title = p.get("track_title") or f"Pipeline #{p['id']}"
text = f"⚠️ [{title}] 파이프라인 #{p['id']} '{step}' 실패\n사유: {reason}"
kb = {"inline_keyboard": [[{"text": "🔄 재시도", "callback_data": f"ytpub_retry_{p['id']}"}]]}
sent = await send_raw(text=text, reply_markup=kb)
if sent.get("ok"):
add_log(self.agent_id, f"pipeline {p['id']} 실패 알림", "warning")
async def _notify_step(self, pipeline: dict) -> None:
state = pipeline["state"]
title_name, step = _STEP_TITLES[state]