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_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",
|
||||
"PORT": 2903,
|
||||
"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)
|
||||
)
|
||||
logger.debug('Inserted Comment into DB, `comment_id`: %s', comment_id)
|
||||
return comment_id
|
||||
|
||||
|
||||
|
|
|
@ -50,17 +50,20 @@ async def create_database_backup(app):
|
|||
helpers.backup_database(conn, app['backup'])
|
||||
|
||||
except asyncio.CancelledError as e:
|
||||
logger.exception('Database backup loop has been cancelled')
|
||||
|
||||
pass
|
||||
|
||||
async def start_background_tasks(app: web.Application):
|
||||
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):
|
||||
logger.debug('Ending background backup loop')
|
||||
app['waitful_backup'].cancel()
|
||||
await app['waitful_backup']
|
||||
app['reader'].close()
|
||||
app['writer'].close()
|
||||
|
||||
|
||||
def create_app(**kwargs):
|
||||
|
@ -84,8 +87,6 @@ async def stop_app(runner):
|
|||
|
||||
|
||||
async def run_app(app, duration=3600):
|
||||
app['comment_scheduler'] = await writes.create_comment_scheduler()
|
||||
app['writer'] = writes.DatabaseWriter(config['PATH']['DEFAULT'])
|
||||
runner = None
|
||||
try:
|
||||
runner = web.AppRunner(app)
|
||||
|
@ -94,11 +95,16 @@ async def run_app(app, duration=3600):
|
|||
await site.start()
|
||||
await asyncio.sleep(duration)
|
||||
except asyncio.CancelledError as cerr:
|
||||
logger.exception('Got cancellation signal', )
|
||||
pass
|
||||
finally:
|
||||
await stop_app(runner)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
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 (
|
||||
CommentId TEXT NOT NULL,
|
||||
LbryClaimId TEXT NOT NULL,
|
||||
|
@ -31,13 +31,13 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
|||
);
|
||||
|
||||
-- indexes
|
||||
DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
||||
CREATE INDEX COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
||||
-- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
||||
CREATE INDEX IF NOT EXISTS COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
||||
|
||||
|
||||
-- VIEWS
|
||||
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
|
||||
-- DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
||||
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
|
||||
FROM CHANNEL AS CHAN
|
||||
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;
|
||||
CREATE VIEW COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
||||
-- DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||
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
|
||||
JOIN COMMENT AS PARENT
|
||||
ON OG.ParentId = PARENT.CommentId
|
||||
|
|
Loading…
Reference in a new issue