Skip to content

Commit

Permalink
Integrate comment handler into app
Browse files Browse the repository at this point in the history
  • Loading branch information
penguineer committed May 3, 2022
1 parent 7db2f3f commit fe3c402
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@

import logging

import comment

LOG_FORMAT = '%(levelname) -10s %(asctime)s %(name) -15s %(lineno) -5d: %(message)s'
LOGGER = logging.getLogger(__name__)


def make_app() -> tornado.web.Application:
def make_app(cmt_cfg, comment_cb) -> tornado.web.Application:
version_path = r"/v[0-9]"
return tornado.web.Application([
(version_path + r"/health", service.HealthHandler),
(version_path + r"/oas3", service.Oas3Handler),
(version_path + r"/comment", comment.CommentHandler, {"cfg": cmt_cfg, "comment_cb": comment_cb}),
])


def cmt_test_cb(cmt: comment.Comment):
LOGGER.info("Received comment %s", cmt)
return True


def main():
# Setup logging
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

# Service Configuration
service_port = os.getenv('SERVICE_PORT', 8080)
cmt_cfg = comment.CommentConfiguration.from_environment()

# Setup ioloop
service.platform_setup()
Expand All @@ -37,7 +46,7 @@ def main():
# Setup Service Management endpoint
mgmt_ep = service.ServiceEndpoint(listen_port=service_port)
guard.add_termination_handler(mgmt_ep.stop)
app = make_app()
app = make_app(cmt_cfg, cmt_test_cb)
mgmt_ep.setup(app)

# Health Provider map uses weak references, so make sure to store this instance in a variable
Expand Down

0 comments on commit fe3c402

Please sign in to comment.