def gunicorn(): """Utility function to run the app with gunicorn""" import main from helpers import exception, init_console exception.init() init_console.init() config = config_loader.main() config.MODE = "production" config.flask.MODE = config.MODE return main.create_app(config.flask, config.mysql)
connection = mysql.connector.connect(**con_options) logger.info("Connected.") except mysql.connector.errors.Error: logger.exception("Error while connecting to mysql: ", exc_info=1) execution: Union[Execute, None] = None try: # Make the tables execution = Execute(connection) execution.start() except mysql.connector.errors.Error as e: logger.error("There was an error while creating tables:") logger.exception(e.msg) # Make sure that everything we did is commited # and the connection is closed, even on a failure execution.cleanUp() if __name__ == "__main__": init() # Initiate the logger if "--log-file" in sys.argv: formatter.init(PROJECT_ROOT, sys.argv[sys.argv.index("--log-file") + 1]) else: formatter.init(PROJECT_ROOT) main()
sys.argv[sys.argv.index("--log-file") + 1]) if "--flask-config" not in sys.argv or "--mysql-config" not in sys.argv: logger.error( "Flask and mysql config are not specified in commandline.") logger = logging.getLogger("server") flask_config = deserialize(sys.argv[sys.argv.index("--flask-config") + 1]) mysql_config = deserialize(sys.argv[sys.argv.index("--mysql-config") + 1]) if flask_config.MODE == "development": run_development_server(flask_config, mysql_config) else: run_production_server(flask_config, mysql_config) if __name__ == "__main__": # If the functions were called as modules, then screen is already initialised # but if the code reaches here, it means that it is not initialised. from helpers import init_console, exception exception.init() init_console.init() main() # Code shouldn't reach here if it is being run as a script logger: logging.Logger = logging.getLogger("server")