-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18add94
commit dbd2b09
Showing
29 changed files
with
379 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,13 @@ | ||
import os | ||
import sys | ||
|
||
python_version = sys.version_info | ||
if not ((3, 11) <= python_version < (3, 13)): | ||
print(f"Python 3.11 or 3.12 is required, current version is {python_version.major}.{python_version.minor}") | ||
raise SystemExit(1) | ||
|
||
from configs import dify_config | ||
|
||
if not dify_config.DEBUG: | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
import grpc.experimental.gevent | ||
|
||
grpc.experimental.gevent.init_gevent() | ||
|
||
import json | ||
import threading | ||
import time | ||
import warnings | ||
|
||
from flask import Response | ||
|
||
from app_factory import create_app | ||
from libs import threadings_utils, version_utils | ||
|
||
# DO NOT REMOVE BELOW | ||
from events import event_handlers # noqa: F401 | ||
from extensions.ext_database import db | ||
|
||
# TODO: Find a way to avoid importing models here | ||
from models import account, dataset, model, source, task, tool, tools, web # noqa: F401 | ||
|
||
# DO NOT REMOVE ABOVE | ||
|
||
|
||
warnings.simplefilter("ignore", ResourceWarning) | ||
|
||
os.environ["TZ"] = "UTC" | ||
# windows platform not support tzset | ||
if hasattr(time, "tzset"): | ||
time.tzset() | ||
|
||
# preparation before creating app | ||
version_utils.check_supported_python_version() | ||
threadings_utils.apply_gevent_threading_patch() | ||
|
||
# create app | ||
app = create_app() | ||
celery = app.extensions["celery"] | ||
|
||
if dify_config.TESTING: | ||
print("App is running in TESTING mode") | ||
|
||
|
||
@app.after_request | ||
def after_request(response): | ||
"""Add Version headers to the response.""" | ||
response.headers.add("X-Version", dify_config.CURRENT_VERSION) | ||
response.headers.add("X-Env", dify_config.DEPLOY_ENV) | ||
return response | ||
|
||
|
||
@app.route("/health") | ||
def health(): | ||
return Response( | ||
json.dumps({"pid": os.getpid(), "status": "ok", "version": dify_config.CURRENT_VERSION}), | ||
status=200, | ||
content_type="application/json", | ||
) | ||
|
||
|
||
@app.route("/threads") | ||
def threads(): | ||
num_threads = threading.active_count() | ||
threads = threading.enumerate() | ||
|
||
thread_list = [] | ||
for thread in threads: | ||
thread_name = thread.name | ||
thread_id = thread.ident | ||
is_alive = thread.is_alive() | ||
|
||
thread_list.append( | ||
{ | ||
"name": thread_name, | ||
"id": thread_id, | ||
"is_alive": is_alive, | ||
} | ||
) | ||
|
||
return { | ||
"pid": os.getpid(), | ||
"thread_num": num_threads, | ||
"threads": thread_list, | ||
} | ||
|
||
|
||
@app.route("/db-pool-stat") | ||
def pool_stat(): | ||
engine = db.engine | ||
return { | ||
"pid": os.getpid(), | ||
"pool_size": engine.pool.size(), | ||
"checked_in_connections": engine.pool.checkedin(), | ||
"checked_out_connections": engine.pool.checkedout(), | ||
"overflow_connections": engine.pool.overflow(), | ||
"connection_timeout": engine.pool.timeout(), | ||
"recycle_time": db.engine.pool._recycle, | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=5001) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Flask | ||
|
||
|
||
class DifyApp(Flask): | ||
pass |
Oops, something went wrong.