Adjusts logger & stops database frop dropping tables on each DDL startup
This commit is contained in:
parent
7d0bd1763f
commit
4b5dd2a505
5 changed files with 21 additions and 14 deletions
|
@ -12,7 +12,7 @@
|
||||||
"CHANNEL_ID": "9cb713f01bf247a0e03170b5ed00d5161340c486",
|
"CHANNEL_ID": "9cb713f01bf247a0e03170b5ed00d5161340c486",
|
||||||
"CHANNEL_NAME": "@Anonymous"
|
"CHANNEL_NAME": "@Anonymous"
|
||||||
},
|
},
|
||||||
"LOGGING_FORMAT": "%(asctime)s - %(name)s - %(level)s - %(message)s",
|
"LOGGING_FORMAT": "%(asctime)s - %(levelname)s - %(module)s - %(funcName)s - %(message)s",
|
||||||
"HOST": "localhost",
|
"HOST": "localhost",
|
||||||
"PORT": 2903,
|
"PORT": 2903,
|
||||||
"BACKUP_INT": 3600
|
"BACKUP_INT": 3600
|
||||||
|
|
0
config/logging.yaml
Normal file
0
config/logging.yaml
Normal file
|
@ -81,6 +81,7 @@ def _insert_comment(conn: sqlite3.Connection, claim_id: str = None, comment: str
|
||||||
""",
|
""",
|
||||||
(comment_id, claim_id, channel_id, comment, parent_id, signature, timestamp)
|
(comment_id, claim_id, channel_id, comment, parent_id, signature, timestamp)
|
||||||
)
|
)
|
||||||
|
logger.debug('Inserted Comment into DB, `comment_id`: %s', comment_id)
|
||||||
return comment_id
|
return comment_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,17 +50,20 @@ async def create_database_backup(app):
|
||||||
helpers.backup_database(conn, app['backup'])
|
helpers.backup_database(conn, app['backup'])
|
||||||
|
|
||||||
except asyncio.CancelledError as e:
|
except asyncio.CancelledError as e:
|
||||||
logger.exception('Database backup loop has been cancelled')
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def start_background_tasks(app: web.Application):
|
async def start_background_tasks(app: web.Application):
|
||||||
app['waitful_backup'] = app.loop.create_task(create_database_backup(app))
|
app['waitful_backup'] = app.loop.create_task(create_database_backup(app))
|
||||||
|
app['comment_scheduler'] = await writes.create_comment_scheduler()
|
||||||
|
app['writer'] = writes.DatabaseWriter(config['PATH']['DEFAULT'])
|
||||||
|
|
||||||
|
|
||||||
async def cleanup_background_tasks(app):
|
async def cleanup_background_tasks(app):
|
||||||
logger.debug('Ending background backup loop')
|
logger.debug('Ending background backup loop')
|
||||||
app['waitful_backup'].cancel()
|
app['waitful_backup'].cancel()
|
||||||
await app['waitful_backup']
|
await app['waitful_backup']
|
||||||
|
app['reader'].close()
|
||||||
|
app['writer'].close()
|
||||||
|
|
||||||
|
|
||||||
def create_app(**kwargs):
|
def create_app(**kwargs):
|
||||||
|
@ -84,8 +87,6 @@ async def stop_app(runner):
|
||||||
|
|
||||||
|
|
||||||
async def run_app(app, duration=3600):
|
async def run_app(app, duration=3600):
|
||||||
app['comment_scheduler'] = await writes.create_comment_scheduler()
|
|
||||||
app['writer'] = writes.DatabaseWriter(config['PATH']['DEFAULT'])
|
|
||||||
runner = None
|
runner = None
|
||||||
try:
|
try:
|
||||||
runner = web.AppRunner(app)
|
runner = web.AppRunner(app)
|
||||||
|
@ -94,11 +95,16 @@ async def run_app(app, duration=3600):
|
||||||
await site.start()
|
await site.start()
|
||||||
await asyncio.sleep(duration)
|
await asyncio.sleep(duration)
|
||||||
except asyncio.CancelledError as cerr:
|
except asyncio.CancelledError as cerr:
|
||||||
logger.exception('Got cancellation signal', )
|
pass
|
||||||
finally:
|
finally:
|
||||||
await stop_app(runner)
|
await stop_app(runner)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
appl = create_app(close_timeout=5.0)
|
appl = create_app(close_timeout=5.0)
|
||||||
asyncio.run(run_app(appl))
|
try:
|
||||||
|
asyncio.run(web.run_app(appl, access_log=logger, host=config['HOST'], port=config['PORT']))
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
|
@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS CHANNEL(
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS COMMENT;
|
-- DROP TABLE IF EXISTS COMMENT;
|
||||||
CREATE TABLE IF NOT EXISTS COMMENT (
|
CREATE TABLE IF NOT EXISTS COMMENT (
|
||||||
CommentId TEXT NOT NULL,
|
CommentId TEXT NOT NULL,
|
||||||
LbryClaimId TEXT NOT NULL,
|
LbryClaimId TEXT NOT NULL,
|
||||||
|
@ -31,13 +31,13 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
||||||
);
|
);
|
||||||
|
|
||||||
-- indexes
|
-- indexes
|
||||||
DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
-- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
||||||
CREATE INDEX COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
CREATE INDEX IF NOT EXISTS COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
||||||
|
|
||||||
|
|
||||||
-- VIEWS
|
-- VIEWS
|
||||||
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
-- DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
||||||
CREATE VIEW COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_uri, signature, parent_id, comment) AS
|
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_uri, signature, parent_id, comment) AS
|
||||||
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.ParentId, C.Body
|
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.ParentId, C.Body
|
||||||
FROM CHANNEL AS CHAN
|
FROM CHANNEL AS CHAN
|
||||||
INNER JOIN COMMENT C on CHAN.ClaimId = C.ChannelId
|
INNER JOIN COMMENT C on CHAN.ClaimId = C.ChannelId
|
||||||
|
@ -45,8 +45,8 @@ CREATE VIEW COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
-- DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||||
CREATE VIEW COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
||||||
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body FROM COMMENT AS OG
|
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body FROM COMMENT AS OG
|
||||||
JOIN COMMENT AS PARENT
|
JOIN COMMENT AS PARENT
|
||||||
ON OG.ParentId = PARENT.CommentId
|
ON OG.ParentId = PARENT.CommentId
|
||||||
|
|
Loading…
Reference in a new issue