각 메서드 로그개선

This commit is contained in:
2023-04-30 10:26:08 +09:00
parent 17757e883e
commit 80688a3187
2 changed files with 53 additions and 40 deletions

View File

@ -10,6 +10,10 @@ app = web.Application()
@routes.get('/get_subscriber/{widget_id}')
async def get_widgets(request):
"""
주어진 widget_id로 연결된 구독 목록을 반환합니다.
사용 예: http://localhost/get_subscriber?widget_id=YOUR_WIDGET_ID
"""
widget_id = request.match_info['widget_id']
subscribers = toonat.get_subscribers(widget_id)
if subscribers:
@ -22,36 +26,39 @@ async def get_widgets(request):
async def subscribe(request):
"""
주어진 widget_id와 url로 구독을 추가합니다.
사용 예: http://localhost/subscribe/YOUR_WIDGET_ID?url=YOUR_WEBHOOK_URL
"""
widget_id = request.match_info['widget_id']
url = request.query['url']
success = toonat.add_subscriber(widget_id, url)
if success:
return web.Response(text=f"Subscribed to widget ID {success} with URL {url}.")
return web.Response(text=f"Subscribed to widget ID {success} with URL {url}")
else:
return web.Response(text=f"Already subscribed to widget ID {widget_id} with URL {url}.")
return web.Response(text=f"Already subscribed to widget ID {widget_id} with URL {url}")
@routes.get('/unsubscribe/{widget_id}')
async def unsubscribe(request):
"""
주어진 widget_id와 url로 구독을 취소합니다.
사용 예: http://localhost/unusbscribe/YOUR_WIDGET_ID?=url=YOUR_WEBHOOK_URL
"""
widget_id = request.match_info['widget_id']
url = request.query['url']
success = toonat.remove_subscriber(widget_id, url)
if success:
return web.Response(text=f"Unsubscribed from widget ID {success} with URL {url}.")
return web.Response(text=f"Unsubscribed from widget ID {success} with URL {url}")
else:
return web.Response(text=f"Not subscribed to widget ID {widget_id} with URL {url}.")
return web.Response(text=f"Not subscribed to widget ID {widget_id} with URL {url}")
@routes.get('/get_widgets')
async def get_widgets(request):
"""
현재 설정된 모든 위젯 ID 목록을 반환하는 웹 API 엔드포인트입니다.
현재 설정된 모든 위젯 ID 목록을 반환니다.
사용 예: http://localhost/get_widgets
"""
widget_ids = toonat.get_widget_ids()
@ -64,29 +71,31 @@ async def get_widgets(request):
@routes.get('/add_widget')
async def add_widget(request):
"""
주어진 widget_id를 위젯 ID 목록에 추가하고 알림을 가져오는 작업을 시작하는 웹 API 엔드포인트입니다.
주어진 widget_id를 위젯 ID 목록에 추가하고 알림을 가져오는 작업을 시작니다.
widget_id: 추가할 위젯 ID
사용 예: http://localhost/add_widget?=widget_id=YOUR_WIDGET_ID
"""
widget_id = request.query['widget_id']
success = await toonat.add_widget_and_start_fetching_notifications(widget_id)
if success:
return web.Response(text=f"Widget ID {success} added and fetching started.")
return web.Response(text=f"Widget ID {success} added and fetching started")
else:
return web.Response(text=f"no widget_ids")
return web.Response(text=f"Already {widget_id} in the list")
@routes.get('/remove_widget')
async def remove_widget(request):
"""
주어진 widget_id를 위젯 ID 목록에서 제거하고 알림을 가져오는 작업을 중단하는 웹 API 엔드포인트입니다.
주어진 widget_id를 위젯 ID 목록에서 제거하고 알림을 가져오는 작업을 중단니다.
widget_id: 제거할 위젯 ID
사용 예: http://localhost/remove_widget?=YOUR_WIDGET_ID
"""
widget_id = request.query['widget_id']
success = await toonat.remove_widget_and_stop_fetching_notifications(widget_id)
if success:
return web.Response(text=f"Widget ID {success} removed and fetching stopped.")
return web.Response(text=f"Widget ID {success} removed and fetching stopped")
else:
return web.Response(text=f"Not in widget list {widget_id}")
@ -95,6 +104,7 @@ async def remove_widget(request):
async def status(request):
"""
서버 상태를 확인하는 웹 API 엔드포인트입니다. 이 엔드포인트는 서버가 정상적으로 작동 중임을 확인하는 데 사용됩니다.
DOCKER Health Check에 사용됩니다.
"""
return web.HTTPOk()
@ -124,7 +134,7 @@ async def main():
if __name__ == "__main__":
if not toonat.WIDGET_IDS:
print("No widget ID found in settings.ini.")
print("Please enter the widget ID via web endpoint (http://localhost/add_widget/YOUR_WIDGET_ID)")
print("settings.ini 파일에서 위젯 ID를 찾을 수 없습니다")
print("웹 엔드포인트(http://localhost/add_widget/YOUR_WIDGET_ID)를 통해 위젯 ID를 입력해주세요")
asyncio.run(main())