각 메서드 로그개선
This commit is contained in:
@ -87,10 +87,10 @@ class DaminationAPI():
|
||||
if widgets[0]:
|
||||
for widget in widgets:
|
||||
await self.add_widget_and_start_fetching_notifications(widget)
|
||||
logger.info(f"initialize wigets : {widgets}")
|
||||
logger.info(f"[initialize_widgets] WIDGET ID 초기화 : {widgets}")
|
||||
|
||||
else:
|
||||
logger.error(f"widgets empty")
|
||||
logger.error(f"[initialize_widgets] WIDGET 초기화 실패 - 등록된 WIDGET ID 없음")
|
||||
|
||||
|
||||
async def process_notification(self):
|
||||
@ -99,9 +99,9 @@ class DaminationAPI():
|
||||
if donate is not None:
|
||||
for widget_id, value in donate.items():
|
||||
await self.send_notifications_to_subscribers(widget_id, value)
|
||||
|
||||
logger.debug(f"[process_notification] QUEUE 추출: {widget_id, value}")
|
||||
else:
|
||||
logger.error("No notifications in the queue, breaking loop.")
|
||||
logger.error("[process_notification] QUEUE 추출 실패 - 저장된 QUEUE 없음")
|
||||
break
|
||||
|
||||
|
||||
@ -113,11 +113,11 @@ class DaminationAPI():
|
||||
|
||||
if widget_id in self.subscribers:
|
||||
subscribers = self.subscribers[widget_id]
|
||||
logger.info(f"get {widget_id} subscribers : {subscribers}")
|
||||
logger.info(f"[get_subscribers] 구독자 반환({widget_id}) : {subscribers}")
|
||||
return subscribers
|
||||
|
||||
else:
|
||||
logger.error(f"no subscribers")
|
||||
logger.error(f"[get_subscribers] 구독자 없음({widget_id})")
|
||||
return []
|
||||
|
||||
|
||||
@ -127,22 +127,22 @@ class DaminationAPI():
|
||||
|
||||
if url not in self.subscribers[widget_id]:
|
||||
self.subscribers[widget_id].append(url)
|
||||
logger.info(f"Added subscriber: widget_id={widget_id}, url={url}")
|
||||
logger.info(f"[add_subscriber] 구독자 추가 widget_id={widget_id}, url={url}")
|
||||
return widget_id
|
||||
|
||||
else:
|
||||
logger.error(f"Subscriber already exists: widget_id={widget_id}, url={url}")
|
||||
logger.error(f"[add_subscriber] 이미 추가된 구독자 widget_id={widget_id}, url={url}")
|
||||
return ''
|
||||
|
||||
|
||||
def remove_subscriber(self, widget_id: str, url: str) -> str:
|
||||
if widget_id in self.subscribers and url in self.subscribers[widget_id]:
|
||||
self.subscribers[widget_id].remove(url)
|
||||
logger.info(f"Removed subscriber: widget_id={widget_id}, url={url}")
|
||||
logger.info(f"[remove_subscriber] 구독자 제거: widget_id={widget_id}, url={url}")
|
||||
return widget_id
|
||||
|
||||
else:
|
||||
logger.error(f"Subscriber not found: widget_id={widget_id}, url={url}")
|
||||
logger.error(f"[remove_subscriber] 구독자를 찾을 수 없음 widget_id={widget_id}, url={url}")
|
||||
return ''
|
||||
|
||||
|
||||
@ -151,11 +151,11 @@ class DaminationAPI():
|
||||
현재 설정된 모든 위젯 ID 목록을 반환합니다.
|
||||
"""
|
||||
if self.WIDGET_IDS:
|
||||
logger.info(f"get widget {self.WIDGET_IDS}")
|
||||
logger.info(f"[get_widget_ids] WIDGET ID 반환 {self.WIDGET_IDS}")
|
||||
return self.WIDGET_IDS
|
||||
|
||||
else:
|
||||
logger.error(f"widget id empty")
|
||||
logger.error(f"[get_widget_ids] WIDGET ID 반환 실패 - WIDGET ID 없음")
|
||||
return []
|
||||
|
||||
|
||||
@ -167,11 +167,11 @@ class DaminationAPI():
|
||||
try:
|
||||
if widget_id not in self.WIDGET_IDS:
|
||||
self.WIDGET_IDS.append(widget_id)
|
||||
logger.info(f"add widget {widget_id}")
|
||||
logger.info(f"[add_widget_id] WIDGET ID 추가 {widget_id}")
|
||||
return widget_id
|
||||
|
||||
else:
|
||||
logger.error(f"{widget_id} already exists in the list.")
|
||||
logger.error(f"[add_widget_id] 이미 추가된 WIDGET ID {widget_id}")
|
||||
return ''
|
||||
|
||||
except Exception as e:
|
||||
@ -188,11 +188,11 @@ class DaminationAPI():
|
||||
try:
|
||||
if widget_id in self.WIDGET_IDS:
|
||||
widget = self.WIDGET_IDS.pop(self.WIDGET_IDS.index(widget_id))
|
||||
logger.info(f"remove widget {widget}")
|
||||
logger.info(f"[remove_widget_id] WIDGET ID 제거 {widget}")
|
||||
return widget
|
||||
|
||||
else:
|
||||
logger.error(f"not in widget")
|
||||
logger.error(f"[remove_widget_id] WIDGET ID 제거 실패 - WIDGET ID를 찾을 수 없음")
|
||||
return ''
|
||||
|
||||
except Exception as e:
|
||||
@ -218,7 +218,7 @@ class DaminationAPI():
|
||||
async with connect(wss_url, ping_interval=12) as websocket:
|
||||
token = json.loads(await websocket.recv())['token']
|
||||
logger.debug(f"token : {token}")
|
||||
logger.info(f"WebSocket connection established for widget_id: {widget_id}")
|
||||
logger.info(f"[fetch_notifications] 웹 소켓 연결 : {widget_id}")
|
||||
while True:
|
||||
|
||||
message = await websocket.recv()
|
||||
@ -229,23 +229,24 @@ class DaminationAPI():
|
||||
reformed_data = Donate(**alert_data)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error: {e}, Raw data: {alert_data}")
|
||||
logger.error(f"[fetch_notifications] Error: {e}, Raw data: {alert_data}")
|
||||
|
||||
pass
|
||||
|
||||
await queue.put({widget_id: json.loads(reformed_data.json().encode('utf-8').decode('unicode_escape'))})
|
||||
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"Widget {widget_id} fetching task was cancelled.")
|
||||
logger.info(f"[fetch_notifications] 웹 소켓 연결 취소 : {widget_id}")
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error: {e}")
|
||||
retries += 1
|
||||
logger.error(f"[fetch_notifications] 웹 소켓 연결 실패 : {e}, 재시도 : {retries}")
|
||||
await asyncio.sleep(2 ** retries)
|
||||
|
||||
self.remove_widget_id(widget_id)
|
||||
logger.info(f"Connection failed for widget_id: {widget_id}")
|
||||
if retries > 2:
|
||||
self.remove_widget_id(widget_id)
|
||||
logger.info(f"[fetch_notifications] 연결 실패 : {widget_id}")
|
||||
|
||||
|
||||
@staticmethod
|
||||
@ -274,10 +275,11 @@ class DaminationAPI():
|
||||
self.add_widget_id(widget_id)
|
||||
task = asyncio.create_task(self.fetch_notifications(self.queue, widget_id))
|
||||
self.fetch_tasks.append(task)
|
||||
logger.info(f"[add_widget_and_start_fetching_notifications] 투네이션 알림 수신 시작 : {widget_id}")
|
||||
return widget_id
|
||||
|
||||
else:
|
||||
logger.error(f"Widget ID {widget_id} already exists in the list.")
|
||||
logger.error(f"[add_widget_and_start_fetching_notifications] 이미 투네이션 알림 수신 중 : {widget_id}")
|
||||
return ''
|
||||
|
||||
|
||||
@ -292,13 +294,14 @@ class DaminationAPI():
|
||||
fetch_task = self.fetch_tasks.pop(index)
|
||||
fetch_task.cancel()
|
||||
await fetch_task
|
||||
logger.info(f"[remove_widget_and_stop_fetching_notifications] 투네이션 알림 수신 중단 : {widget_id}")
|
||||
return widget_id
|
||||
else:
|
||||
logger.error(f"Widget ID {widget_id} not found.")
|
||||
logger.error(f"[remove_widget_and_stop_fetching_notifications] 수신중인 투네이션 알림을 찾을 수 없음 {widget_id}")
|
||||
return ''
|
||||
|
||||
|
||||
async def pop_notification_from_queue(self):
|
||||
async def pop_notification_from_queue(self) -> dict:
|
||||
"""
|
||||
queue에서 가장 먼저 저장된 항목을 꺼내어 반환합니다.
|
||||
queue가 비어있는 경우 None을 반환합니다.
|
||||
@ -307,7 +310,7 @@ class DaminationAPI():
|
||||
item = await self.queue.get()
|
||||
return item
|
||||
else:
|
||||
return None
|
||||
return {}
|
||||
|
||||
|
||||
async def get_connection(self, url: str):
|
||||
@ -335,9 +338,9 @@ class DaminationAPI():
|
||||
|
||||
async with session.post(subscriber_url, json=payload) as response:
|
||||
if response.status == 200:
|
||||
logger.info(f"Successfully sent Webhook to {subscriber_url}, {payload}")
|
||||
logger.info(f"[send_notification_webhook] 알림 전송 {subscriber_url}, {payload}")
|
||||
else:
|
||||
logger.error(f"Failed to send notification to {subscriber_url} with status code {response.status}.")
|
||||
logger.error(f"[send_notification_webhook] 알림 전송 실패 {subscriber_url}, 응답: {response.status}")
|
||||
|
||||
|
||||
async def run(self):
|
||||
|
||||
Reference in New Issue
Block a user