X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fbootstrap.py;fp=o2ims%2Fbootstrap.py;h=595fd91707d8c5a6c4935a5e45c59ce3bcdb474a;hb=cb9a72de554108746c4ed35f8ad9e0a5550f626d;hp=10bdc266c658ee1365914f2401dc31533ea57cad;hpb=b21c925328b0c700fde9001b7a56ea55decdf088;p=pti%2Fo2.git diff --git a/o2ims/bootstrap.py b/o2ims/bootstrap.py index 10bdc26..595fd91 100644 --- a/o2ims/bootstrap.py +++ b/o2ims/bootstrap.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from retry import retry import inspect from typing import Callable from o2ims.adapter import orm, redis_eventpublisher @@ -21,6 +22,16 @@ from o2ims.adapter.notifications import AbstractNotifications,\ from o2ims.service import handlers, messagebus, unit_of_work from o2ims.adapter.unit_of_work import SqlAlchemyUnitOfWork from o2ims.adapter.clients import orm_stx +from o2common.helper import o2logging +logger = o2logging.get_logger(__name__) + + +@retry(tries=100, delay=2, backoff=1) +def wait_for_db_ready(engine): + # wait for db up + logger.info("Wait for DB ready ...") + engine.connect() + logger.info("DB is ready") def bootstrap( @@ -34,12 +45,14 @@ def bootstrap( notifications = SmoO2Notifications() if start_orm: - orm_stx.start_o2ims_stx_mappers(uow) with uow: # get default engine if uow is by default engine = uow.session.get_bind() + wait_for_db_ready(engine) orm.start_o2ims_mappers(engine) + orm_stx.start_o2ims_stx_mappers(uow) + dependencies = {"uow": uow, "notifications": notifications, "publish": publish} injected_event_handlers = {