Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
f7ead397
Commit
f7ead397
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
be7084bb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
6 deletions
+71
-6
application/__init__.py
application/__init__.py
+0
-2
application/extensions/__init__.py
application/extensions/__init__.py
+31
-1
application/extensions/init_apscheduler.py
application/extensions/init_apscheduler.py
+1
-1
application/extensions/init_consul.py
application/extensions/init_consul.py
+21
-0
application/extensions/init_dotenv.py
application/extensions/init_dotenv.py
+18
-2
No files found.
application/__init__.py
View file @
f7ead397
...
...
@@ -44,7 +44,5 @@ def create_app() -> Flask:
# This could include data migration scripts, administrative tasks, etc.
init_script
(
app
)
print
(
app
.
config
)
# Return the fully initialized Flask application
return
app
application/extensions/__init__.py
View file @
f7ead397
...
...
@@ -13,6 +13,7 @@
from
flask
import
Flask
# Import the initialization functions in alphabetical order
from
.init_apispec
import
init_apispec
from
.init_apscheduler
import
init_tasks
from
.init_config
import
init_config
...
...
@@ -23,14 +24,43 @@ from .init_elasticsearch import init_elasticsearch
from
.init_logger
import
init_logger
from
.init_sqlalchemy
import
init_database
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
()
# Initialize the application configuration
init_config
(
app
)
# Initialize the application logging
init_logger
(
app
)
# Initialize the database connection
init_database
(
app
)
# Initialize the API specification
init_apispec
(
app
)
# Initialize the Elasticsearch client
init_elasticsearch
(
app
)
# Initialize the CORS policy
init_cors
(
app
)
# Initialize the Consul client
init_consul
(
app
)
# Initialize the scheduled tasks
init_tasks
(
app
)
application/extensions/init_apscheduler.py
View file @
f7ead397
...
...
@@ -13,8 +13,8 @@
from
apscheduler.triggers.interval
import
IntervalTrigger
from
flask
import
Flask
from
application.libs.tasks
import
task
from
application.libs.flask_apscheduler
import
APScheduler
from
application.libs.tasks
import
task
scheduler
=
APScheduler
()
...
...
application/extensions/init_consul.py
View file @
f7ead397
...
...
@@ -10,10 +10,31 @@
# @Description :
"""
# Import built-in modules
from
flask
import
Flask
# Import custom modules
from
application.libs
import
FlaskConsulService
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
)
application/extensions/init_dotenv.py
View file @
f7ead397
...
...
@@ -10,18 +10,34 @@
# @Description :
"""
# Import standard library modules
import
os
# Import third-party library modules
from
dotenv
import
load_dotenv
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
]
# Construct the path to the .flaskenv file
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
):
load_dotenv
(
flask_env_path
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment