mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-04-13 05:17:12 +03:00
Add logging for models
This commit is contained in:
parent
1a692df820
commit
702ab34154
@ -21,8 +21,9 @@ elif env_choose == 'sqlite':
|
||||
model = Sqlite3Model()
|
||||
|
||||
else:
|
||||
logger.info('Using sqlite DB')
|
||||
model = Sqlite3Model()
|
||||
logger.error(f'Unknown DB {env_choose!r}')
|
||||
|
||||
assert False, 'env variable DB_NAME must be "postgres" or "sqlite"'
|
||||
|
||||
model.open_model()
|
||||
|
||||
|
@ -27,12 +27,15 @@ class PostgresModel(AbstractModel):
|
||||
database=os.environ['DB_DATABASE'], # test0
|
||||
cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
||||
logger.info(f'Connected to {self.db.dsn}')
|
||||
|
||||
with self.db:
|
||||
with self.db.cursor() as cursor:
|
||||
cursor.execute(postgres_sql_requests.schema_create) # schema creation
|
||||
|
||||
def close_model(self):
|
||||
self.db.close()
|
||||
logger.info(f'Connection to {self.db.dsn} closed successfully')
|
||||
|
||||
def get_activity_changes(self, platform: str, leaderboard_type: str, limit: int, low_timestamp, high_timestamp)\
|
||||
-> list:
|
||||
|
@ -18,6 +18,8 @@ class Sqlite3Model(AbstractModel):
|
||||
def open_model(self):
|
||||
self.db = sqlite3.connect('squads_stat.sqlite3', check_same_thread=False)
|
||||
|
||||
logger.debug(f'Connected to squads_stat.sqlite3')
|
||||
|
||||
self.db.executescript(sqlite_sql_requests.schema_create) # schema creation
|
||||
|
||||
# thx https://stackoverflow.com/a/48789604
|
||||
@ -25,6 +27,7 @@ class Sqlite3Model(AbstractModel):
|
||||
|
||||
def close_model(self):
|
||||
self.db.close()
|
||||
logger.info(f'Connection to squads_stat.sqlite3 closed successfully')
|
||||
|
||||
def get_activity_changes(self, platform: str, leaderboard_type: str, limit: int, low_timestamp, high_timestamp)\
|
||||
-> list:
|
||||
|
Loading…
x
Reference in New Issue
Block a user