diff --git a/api/commands.py b/api/commands.py index e7f54c7cc0..ea82fef397 100644 --- a/api/commands.py +++ b/api/commands.py @@ -26,6 +26,7 @@ from models.dataset import Document as DatasetDocument from models.model import Account, App, AppAnnotationSetting, AppMode, Conversation, MessageAnnotation from models.provider import Provider, ProviderModel from services.account_service import RegisterService, TenantService +from services.clear_free_plan_tenant_expired_logs import ClearFreePlanTenantExpiredLogs from services.plugin.data_migration import PluginDataMigration from services.plugin.plugin_migration import PluginMigration @@ -792,3 +793,23 @@ def install_plugins(input_file: str, output_file: str, workers: int): PluginMigration.install_plugins(input_file, output_file, workers) click.echo(click.style("Install plugins completed.", fg="green")) + + +@click.command("clear-free-plan-tenant-expired-logs", help="Clear free plan tenant expired logs.") +@click.option("--days", prompt=True, help="The days to clear free plan tenant expired logs.", default=30) +@click.option("--batch", prompt=True, help="The batch size to clear free plan tenant expired logs.", default=100) +@click.option( + "--tenant_ids", + prompt=True, + multiple=True, + help="The tenant ids to clear free plan tenant expired logs.", +) +def clear_free_plan_tenant_expired_logs(days: int, batch: int, tenant_ids: list[str]): + """ + Clear free plan tenant expired logs. + """ + click.echo(click.style("Starting clear free plan tenant expired logs.", fg="white")) + + ClearFreePlanTenantExpiredLogs.process(days, batch, tenant_ids) + + click.echo(click.style("Clear free plan tenant expired logs completed.", fg="green")) diff --git a/api/extensions/ext_commands.py b/api/extensions/ext_commands.py index 92996f75e5..be43f55ea7 100644 --- a/api/extensions/ext_commands.py +++ b/api/extensions/ext_commands.py @@ -4,6 +4,7 @@ from dify_app import DifyApp def init_app(app: DifyApp): from commands import ( add_qdrant_index, + clear_free_plan_tenant_expired_logs, convert_to_agent_apps, create_tenant, extract_plugins, @@ -34,6 +35,7 @@ def init_app(app: DifyApp): extract_unique_plugins, install_plugins, old_metadata_migration, + clear_free_plan_tenant_expired_logs, ] for cmd in cmds_to_register: app.cli.add_command(cmd) diff --git a/api/models/model.py b/api/models/model.py index 0a5256c335..05bc1fd301 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -838,6 +838,33 @@ class Conversation(db.Model): # type: ignore[name-defined] def in_debug_mode(self): return self.override_model_configs is not None + def to_dict(self): + return { + "id": self.id, + "app_id": self.app_id, + "app_model_config_id": self.app_model_config_id, + "model_provider": self.model_provider, + "override_model_configs": self.override_model_configs, + "model_id": self.model_id, + "mode": self.mode, + "name": self.name, + "summary": self.summary, + "inputs": self.inputs, + "introduction": self.introduction, + "system_instruction": self.system_instruction, + "system_instruction_tokens": self.system_instruction_tokens, + "status": self.status, + "invoke_from": self.invoke_from, + "from_source": self.from_source, + "from_end_user_id": self.from_end_user_id, + "from_account_id": self.from_account_id, + "read_at": self.read_at, + "read_account_id": self.read_account_id, + "dialogue_count": self.dialogue_count, + "created_at": self.created_at, + "updated_at": self.updated_at, + } + class Message(db.Model): # type: ignore[name-defined] __tablename__ = "messages"