Skip to content

Commit

Permalink
fix: failed to recover log consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Oct 17, 2023
1 parent 4e34668 commit e54f974
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions free_one_api/impls/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import asyncio
import traceback

from ..models.database import db

Expand All @@ -17,9 +18,12 @@ def __init__(self, dbmgr: db.DatabaseInterface, level=logging.NOTSET):

async def _consumer(self):
while True:
record: logging.LogRecord = await self.queue.get()
await self.dbmgr.insert_log(record.created, record.getMessage())
self.queue.task_done()
try:
record: logging.LogRecord = await self.queue.get()
await self.dbmgr.insert_log(record.created, record.getMessage())
self.queue.task_done()
except Exception as e:
print(traceback.format_exc())

def emit(self, record: logging.LogRecord):
"""Emit a record."""
Expand Down

0 comments on commit e54f974

Please sign in to comment.