Commit 81bc5a5c authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

wait for the mysql server to be ready (at controller startup)

parent 5fbbcd64
......@@ -1541,6 +1541,26 @@ class DockerController:
self.check_db()
@asyncio.coroutine
def db_startup(self):
log.info("wait until the db server is ready")
ses = self.session
while True:
with contextlib.suppress(sqlalchemy.exc.OperationalError):
log.debug("db ping")
with ses.begin():
ses.execute("SELECT 1")
break
with contextlib.suppress(asyncio.TimeoutError):
yield from asyncio.wait_for(asyncio.shield(self._shutdown_requested), 10)
return
log.info("db server ready")
self.check_db(startup=True)
def check_db(self, *, startup=False):
log.debug("check_db(startup=%r)", startup)
try:
......@@ -1592,7 +1612,7 @@ class DockerController:
loop.add_signal_handler(signal.SIGINT, self.shutdown)
loop.add_reader(self.sock, self._sock_callback)
self.check_db(startup=True)
yield from self.db_startup()
try:
yield from self._shutdown_requested
finally:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment