Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no pool recycle #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions services/metadata_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from services.data.postgres_async_db import AsyncPostgresDB
from services.utils import DBConfiguration

import logging
import time


def app(loop=None, db_conf: DBConfiguration = None, middlewares=None):

Expand All @@ -33,19 +36,42 @@ def app(loop=None, db_conf: DBConfiguration = None, middlewares=None):


def main():
loop = asyncio.get_event_loop()
the_app = app(loop, DBConfiguration())
handler = the_app.make_handler()
port = os.environ.get("MF_METADATA_PORT", 8080)
host = str(os.environ.get("MF_METADATA_HOST", "0.0.0.0"))
f = loop.create_server(handler, host, port)

srv = loop.run_until_complete(f)
print("serving on", srv.sockets[0].getsockname())
try:
loop.run_forever()
except KeyboardInterrupt:
pass
is_iam = os.environ.get("MF_METADATA_USE_IAM", "False") == "True"
if not is_iam:
loop = asyncio.get_event_loop()
the_app = app(loop, DBConfiguration())
handler = the_app.make_handler()
port = os.environ.get("MF_METADATA_PORT", 8080)
host = str(os.environ.get("MF_METADATA_HOST", "0.0.0.0"))
f = loop.create_server(handler, host, port)

srv = loop.run_until_complete(f)
print("serving on", srv.sockets[0].getsockname())
try:
loop.run_forever()
except KeyboardInterrupt:
pass
else:
loop = asyncio.get_event_loop()
port = os.environ.get("MF_METADATA_PORT", 8080)
host = str(os.environ.get("MF_METADATA_HOST", "0.0.0.0"))

while True:
logging.info("IAM LOOP STARTING")
the_app = app(loop, DBConfiguration())
handler = the_app.make_handler()
f = loop.create_server(handler, host, port)

srv = loop.run_until_complete(f)
print("serving on", srv.sockets[0].getsockname())
try:
loop.run_forever()
logging.info("IAM LOOPING")
time.sleep(900)
loop.stop()
logging.info("IAM LOOP STOPPED")
except KeyboardInterrupt:
pass


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions services/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def connection_string_url(self):

@property
def dsn(self):
logging.info("Asking for Dsn")
if self._dsn is None:
ssl_mode = self._ssl_mode
sslcert = self._ssl_cert_path
Expand Down