diff --git a/api/app_factory.py b/api/app_factory.py index 6e4af75477f36e..deab9d4cf11489 100644 --- a/api/app_factory.py +++ b/api/app_factory.py @@ -1,26 +1,14 @@ import os -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() - - from flask import Flask -from commands import register_commands from configs import dify_config from extensions import ( ext_app_metrics, ext_blueprints, ext_celery, ext_code_based_extension, + ext_commands, ext_compress, ext_database, ext_hosting_provider, @@ -67,8 +55,6 @@ def create_app() -> Flask: app = create_flask_app_with_configs() app.secret_key = dify_config.SECRET_KEY initialize_extensions(app) - register_commands(app) - return app @@ -92,6 +78,7 @@ def initialize_extensions(app: Flask): ext_sentry, ext_proxy_fix, ext_blueprints, + ext_commands, ] for ext in extensions: ext.init_app(app) diff --git a/api/commands.py b/api/commands.py index 23787f38bf0e10..b6f3b52d047867 100644 --- a/api/commands.py +++ b/api/commands.py @@ -640,15 +640,3 @@ def fix_app_site_missing(): break click.echo(click.style("Fix for missing app-related sites completed successfully!", fg="green")) - - -def register_commands(app): - app.cli.add_command(reset_password) - app.cli.add_command(reset_email) - app.cli.add_command(reset_encrypt_key_pair) - app.cli.add_command(vdb_migrate) - app.cli.add_command(convert_to_agent_apps) - app.cli.add_command(add_qdrant_doc_id_index) - app.cli.add_command(create_tenant) - app.cli.add_command(upgrade_db) - app.cli.add_command(fix_app_site_missing) diff --git a/api/extensions/ext_commands.py b/api/extensions/ext_commands.py new file mode 100644 index 00000000000000..48178e472c9f4f --- /dev/null +++ b/api/extensions/ext_commands.py @@ -0,0 +1,25 @@ +from flask import Flask + + +def init_app(app: Flask): + from commands import ( + add_qdrant_doc_id_index, + convert_to_agent_apps, + create_tenant, + fix_app_site_missing, + reset_email, + reset_encrypt_key_pair, + reset_password, + upgrade_db, + vdb_migrate, + ) + + app.cli.add_command(reset_password) + app.cli.add_command(reset_email) + app.cli.add_command(reset_encrypt_key_pair) + app.cli.add_command(vdb_migrate) + app.cli.add_command(convert_to_agent_apps) + app.cli.add_command(add_qdrant_doc_id_index) + app.cli.add_command(create_tenant) + app.cli.add_command(upgrade_db) + app.cli.add_command(fix_app_site_missing)