Commit f7ead397 authored by 崔为之's avatar 崔为之 💪🏽

Update project

parent be7084bb
...@@ -44,7 +44,5 @@ def create_app() -> Flask: ...@@ -44,7 +44,5 @@ def create_app() -> Flask:
# This could include data migration scripts, administrative tasks, etc. # This could include data migration scripts, administrative tasks, etc.
init_script(app) init_script(app)
print(app.config)
# Return the fully initialized Flask application # Return the fully initialized Flask application
return app return app
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
from flask import Flask from flask import Flask
# Import the initialization functions in alphabetical order
from .init_apispec import init_apispec from .init_apispec import init_apispec
from .init_apscheduler import init_tasks from .init_apscheduler import init_tasks
from .init_config import init_config from .init_config import init_config
...@@ -23,14 +24,43 @@ from .init_elasticsearch import init_elasticsearch ...@@ -23,14 +24,43 @@ from .init_elasticsearch import init_elasticsearch
from .init_logger import init_logger from .init_logger import init_logger
from .init_sqlalchemy import init_database from .init_sqlalchemy import init_database
def init_plugs(app: Flask) -> None: def init_plugs(app: Flask) -> None:
"""
This function initializes various plugins for a Flask application.
It accepts a Flask application instance as an argument, and calls a series of initialization
functions on this instance, setting up several plugins.
Each plugin is initialized by a function imported from a separate module. These initialization
functions should take the Flask application instance as an argument, and set up the plugin for
this instance.
Note that the order in which these plugins are initialized can be important, as some plugins may
depend on others being already initialized.
"""
# Initialize the environment variables
init_dotenv() init_dotenv()
# Initialize the application configuration
init_config(app) init_config(app)
# Initialize the application logging
init_logger(app) init_logger(app)
# Initialize the database connection
init_database(app) init_database(app)
# Initialize the API specification
init_apispec(app) init_apispec(app)
# Initialize the Elasticsearch client
init_elasticsearch(app) init_elasticsearch(app)
# Initialize the CORS policy
init_cors(app) init_cors(app)
# Initialize the Consul client
init_consul(app) init_consul(app)
# Initialize the scheduled tasks
init_tasks(app) init_tasks(app)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.interval import IntervalTrigger
from flask import Flask from flask import Flask
from application.libs.tasks import task
from application.libs.flask_apscheduler import APScheduler from application.libs.flask_apscheduler import APScheduler
from application.libs.tasks import task
scheduler = APScheduler() scheduler = APScheduler()
......
...@@ -10,10 +10,31 @@ ...@@ -10,10 +10,31 @@
# @Description : # @Description :
""" """
# Import built-in modules
from flask import Flask from flask import Flask
# Import custom modules
from application.libs import FlaskConsulService from application.libs import FlaskConsulService
def init_consul(app: Flask) -> None: def init_consul(app: Flask) -> None:
"""
Initialize the Consul service.
This function creates an instance of the FlaskConsulService class, passing
the Flask application instance as an argument. This sets up the Consul
service for the Flask application.
Consul is a service networking solution to automate network configurations,
discover services, and enable secure connectivity across any cloud or runtime.
Args:
app (Flask): The Flask application instance.
Returns:
None
"""
# Initialize the FlaskConsulService with the Flask application instance.
# The FlaskConsulService constructor is responsible for setting up
# the Consul service for the Flask application.
FlaskConsulService(app) FlaskConsulService(app)
...@@ -10,18 +10,34 @@ ...@@ -10,18 +10,34 @@
# @Description : # @Description :
""" """
# Import standard library modules
import os import os
# Import third-party library modules
from dotenv import load_dotenv from dotenv import load_dotenv
def init_dotenv() -> None: def init_dotenv() -> None:
""" """
Initialize the dotenv extension Initialize the dotenv extension.
:return: None This function locates the `.flaskenv` file at the root of the project
and loads it into environment variables using the dotenv package.
The `.flaskenv` file is a convenient place to put configuration variables
that should be set early in the application's life cycle, such as
settings for the Flask command-line interface.
Returns:
None
""" """
# Get the root path to the project by removing the 'extensions'
# part from the current file's absolute path
root_path = os.path.abspath(os.path.dirname(__file__)).split('extensions')[0] root_path = os.path.abspath(os.path.dirname(__file__)).split('extensions')[0]
# Construct the path to the .flaskenv file
flask_env_path = os.path.join(root_path, '.flaskenv') flask_env_path = os.path.join(root_path, '.flaskenv')
# If the .flaskenv file exists, load it into environment variables
if os.path.exists(flask_env_path): if os.path.exists(flask_env_path):
load_dotenv(flask_env_path) load_dotenv(flask_env_path)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment