Skip to content

Commit

Permalink
Async restart (#41)
Browse files Browse the repository at this point in the history
* update

* [add] callback to ioloop

* [add] logging

Co-authored-by: Sylvan Zheng <squidgetx@gmail.com>
  • Loading branch information
tngzng and squidgetx authored Mar 15, 2022
1 parent 77fe160 commit 9702d02
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import tornado.autoreload
import tornado.web
from db.mappings.base import db_proxy

from handlers import recommendation, base, model
from lib.config import config
Expand Down Expand Up @@ -64,6 +65,15 @@ async def empty_metric_buffers():
)


async def restart_db_connection():
INTERVAL_MIN = 1
while True:
await asyncio.sleep(INTERVAL_MIN * 60)
if db_proxy.is_closed():
logging.info("Resetting db conn...")
db_proxy.connect()


if __name__ == "__main__":
if config.get("DEBUG") is True:
tornado.autoreload.start()
Expand All @@ -80,4 +90,5 @@ async def empty_metric_buffers():
http_server.listen(port)
io_loop = tornado.ioloop.IOLoop.current()
io_loop.add_callback(empty_metric_buffers)
io_loop.add_callback(restart_db_connection)
io_loop.start()

0 comments on commit 9702d02

Please sign in to comment.