mirror of
https://github.com/langgenius/dify.git
synced 2026-02-27 03:45:09 +00:00
Merge remote-tracking branch 'origin/main' into feat/trigger
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
import time
|
||||
from typing import Optional, TypedDict
|
||||
from typing import TypedDict
|
||||
|
||||
import click
|
||||
from sqlalchemy import func, select
|
||||
@@ -17,7 +17,7 @@ from services.feature_service import FeatureService
|
||||
|
||||
class CleanupConfig(TypedDict):
|
||||
clean_day: datetime.datetime
|
||||
plan_filter: Optional[str]
|
||||
plan_filter: str | None
|
||||
add_logs: bool
|
||||
|
||||
|
||||
@@ -96,11 +96,11 @@ def clean_unused_datasets_task():
|
||||
break
|
||||
|
||||
for dataset in datasets:
|
||||
dataset_query = (
|
||||
db.session.query(DatasetQuery)
|
||||
.where(DatasetQuery.created_at > clean_day, DatasetQuery.dataset_id == dataset.id)
|
||||
.all()
|
||||
)
|
||||
dataset_query = db.session.scalars(
|
||||
select(DatasetQuery).where(
|
||||
DatasetQuery.created_at > clean_day, DatasetQuery.dataset_id == dataset.id
|
||||
)
|
||||
).all()
|
||||
|
||||
if not dataset_query or len(dataset_query) == 0:
|
||||
try:
|
||||
@@ -121,15 +121,13 @@ def clean_unused_datasets_task():
|
||||
if should_clean:
|
||||
# Add auto disable log if required
|
||||
if add_logs:
|
||||
documents = (
|
||||
db.session.query(Document)
|
||||
.where(
|
||||
documents = db.session.scalars(
|
||||
select(Document).where(
|
||||
Document.dataset_id == dataset.id,
|
||||
Document.enabled == True,
|
||||
Document.archived == False,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
).all()
|
||||
for document in documents:
|
||||
dataset_auto_disable_log = DatasetAutoDisableLog(
|
||||
tenant_id=dataset.tenant_id,
|
||||
|
||||
@@ -77,7 +77,7 @@ def clean_workflow_runlogs_precise():
|
||||
|
||||
logger.info("Cleanup completed: %s expired workflow run logs deleted", total_deleted)
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
logger.exception("Unexpected error in workflow log cleanup")
|
||||
raise
|
||||
@@ -149,7 +149,7 @@ def _delete_batch_with_retry(workflow_run_ids: list[str], attempt_count: int) ->
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
logger.exception("Batch deletion failed (attempt %s)", attempt_count + 1)
|
||||
return False
|
||||
|
||||
@@ -3,6 +3,7 @@ import time
|
||||
from collections import defaultdict
|
||||
|
||||
import click
|
||||
from sqlalchemy import select
|
||||
|
||||
import app
|
||||
from configs import dify_config
|
||||
@@ -31,9 +32,9 @@ def mail_clean_document_notify_task():
|
||||
|
||||
# send document clean notify mail
|
||||
try:
|
||||
dataset_auto_disable_logs = (
|
||||
db.session.query(DatasetAutoDisableLog).where(DatasetAutoDisableLog.notified == False).all()
|
||||
)
|
||||
dataset_auto_disable_logs = db.session.scalars(
|
||||
select(DatasetAutoDisableLog).where(DatasetAutoDisableLog.notified == False)
|
||||
).all()
|
||||
# group by tenant_id
|
||||
dataset_auto_disable_logs_map: dict[str, list[DatasetAutoDisableLog]] = defaultdict(list)
|
||||
for dataset_auto_disable_log in dataset_auto_disable_logs:
|
||||
|
||||
@@ -63,10 +63,10 @@ def queue_monitor_task():
|
||||
"alert_time": current_time,
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception(click.style("Exception occurred during sending email", fg="red"))
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception(click.style("Exception occurred during queue monitoring", fg="red"))
|
||||
finally:
|
||||
if db.session.is_active:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import time
|
||||
from collections.abc import Sequence
|
||||
|
||||
import click
|
||||
from sqlalchemy import select
|
||||
|
||||
import app
|
||||
from configs import dify_config
|
||||
@@ -15,11 +17,9 @@ def update_tidb_serverless_status_task():
|
||||
start_at = time.perf_counter()
|
||||
try:
|
||||
# check the number of idle tidb serverless
|
||||
tidb_serverless_list = (
|
||||
db.session.query(TidbAuthBinding)
|
||||
.where(TidbAuthBinding.active == False, TidbAuthBinding.status == "CREATING")
|
||||
.all()
|
||||
)
|
||||
tidb_serverless_list = db.session.scalars(
|
||||
select(TidbAuthBinding).where(TidbAuthBinding.active == False, TidbAuthBinding.status == "CREATING")
|
||||
).all()
|
||||
if len(tidb_serverless_list) == 0:
|
||||
return
|
||||
# update tidb serverless status
|
||||
@@ -32,7 +32,7 @@ def update_tidb_serverless_status_task():
|
||||
click.echo(click.style(f"Update tidb serverless status task success latency: {end_at - start_at}", fg="green"))
|
||||
|
||||
|
||||
def update_clusters(tidb_serverless_list: list[TidbAuthBinding]):
|
||||
def update_clusters(tidb_serverless_list: Sequence[TidbAuthBinding]):
|
||||
try:
|
||||
# batch 20
|
||||
for i in range(0, len(tidb_serverless_list), 20):
|
||||
|
||||
Reference in New Issue
Block a user