blob: e93726753ebad4ed2f748ecaef59a79531dd4a5f [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file or at
4# https://developers.google.com/open-source/licenses/bsd
5
6"""Main program for Monorail.
7
8Monorail is an issue tracking tool that is based on the code.google.com
9issue tracker, but it has been ported to Google AppEngine and Google Cloud SQL.
10"""
11from __future__ import print_function
12from __future__ import division
13from __future__ import absolute_import
14
15import logging
16import webapp2
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020017from flask import Flask
18from werkzeug.middleware import dispatcher
Copybara854996b2021-09-07 19:36:02 +000019
20from components import endpoints_webapp2
Copybara854996b2021-09-07 19:36:02 +000021import gae_ts_mon
22
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020023import flaskregisterpages
Copybara854996b2021-09-07 19:36:02 +000024import registerpages
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020025from framework import sorting, urls
Copybara854996b2021-09-07 19:36:02 +000026from services import api_svc_v1
27from services import service_manager
28
29
30services = service_manager.set_up_services()
31sorting.InitializeArtValues(services)
32registry = registerpages.ServletRegistry()
33app_routes = registry.Register(services)
34app = webapp2.WSGIApplication(
35 app_routes, config={'services': services})
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020036# TODO(crbug.com/1322775) Migrate away from the shared prodx-mon-chrome-infra
37# service account and change to gae_ts_mon.initialize_prod()
38gae_ts_mon.initialize_adhoc(app)
39
40flask_regist = flaskregisterpages.ServletRegistry()
41
42app = dispatcher.DispatcherMiddleware(
43 app, {
44 urls.EXCESSIVE_ACTIVITY:
45 flask_regist.RegisterExcesiveActivity(services),
46 })
Copybara854996b2021-09-07 19:36:02 +000047
48endpoints = endpoints_webapp2.api_server(
49 [api_svc_v1.MonorailApi, api_svc_v1.ClientConfigApi])
50
51# TODO(crbug/monorail/8221): Remove this code during this milestone.
52# It only serves as a safe way to begin connecting to redis without risking
53# user facing problems.
54try:
55 logging.info('Starting initial redis connection verification.')
56 from framework import redis_utils
57 redis_utils.AsyncVerifyRedisConnection()
58except: # pylint: disable=bare-except
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020059 logging.exception('Exception when instantiating redis connection.')