Put db in the constructor

This commit is contained in:
Vladan Popovic 2020-09-06 00:50:01 +02:00
parent 3ec541c3f5
commit af6d59ca97
1 changed files with 9 additions and 4 deletions

View File

@ -11,13 +11,16 @@ import aiokafka # type: ignore
import asyncpg # type: ignore import asyncpg # type: ignore
from chweb.base import Service from chweb.base import Service
from chweb.models import Check, PostgresConfig from chweb.models import Check, Config, PostgresConfig
class Consumer(Service): class Consumer(Service):
@property def __init__(self, config: Config,
def db(self): logger: logging.Logger,
return Db(self.loop, self.logger, self.config.postgres) event_loop: asyncio.AbstractEventLoop,
queue: asyncio.Queue):
super().__init__(config, logger, event_loop, queue)
self.db = Db(self.loop, self.logger, self.config.postgres)
async def consume(self): async def consume(self):
""" """
@ -41,6 +44,8 @@ class Consumer(Service):
except Exception as exc: except Exception as exc:
err = "error processing message %s; failed with %s" err = "error processing message %s; failed with %s"
self.logger.error(err, msg, exc) self.logger.error(err, msg, exc)
except Exception as exc:
self.logger.error(exc)
finally: finally:
await consumer.stop() await consumer.stop()