feat(automation): 持久执行队列与重复充值确认
This commit is contained in:
@@ -48,7 +48,7 @@ from loguru import logger
|
||||
from sqlalchemy import and_, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ....models import AutomationJob, DouyuTask
|
||||
from ....models import AutomationJob, DouyuTask, ExecutionJob, ExecutionJobEvent
|
||||
|
||||
JOB_KEY = "douyu_tasks_retention"
|
||||
|
||||
@@ -202,6 +202,53 @@ def run_douyu_tasks_retention(db: Session, job: AutomationJob) -> dict[str, Any]
|
||||
break
|
||||
per_pass[label] = deleted_this_pass
|
||||
|
||||
deleted_execution_events = 0
|
||||
deleted_execution_jobs = 0
|
||||
if batches < max_batches:
|
||||
event_ids = [
|
||||
int(row[0])
|
||||
for row in (
|
||||
db.query(ExecutionJobEvent.id)
|
||||
.filter(ExecutionJobEvent.created_at < business_cutoff)
|
||||
.order_by(ExecutionJobEvent.id.asc())
|
||||
.limit(batch)
|
||||
.all()
|
||||
)
|
||||
]
|
||||
if event_ids:
|
||||
deleted_execution_events = int(
|
||||
db.query(ExecutionJobEvent)
|
||||
.filter(ExecutionJobEvent.id.in_(event_ids))
|
||||
.delete(synchronize_session=False)
|
||||
or 0
|
||||
)
|
||||
batches += 1
|
||||
db.commit()
|
||||
if batches < max_batches:
|
||||
job_ids = [
|
||||
int(row[0])
|
||||
for row in (
|
||||
db.query(ExecutionJob.id)
|
||||
.filter(
|
||||
ExecutionJob.status.in_(("succeeded", "failed", "cancelled")),
|
||||
ExecutionJob.finished_at.isnot(None),
|
||||
ExecutionJob.finished_at < business_cutoff,
|
||||
)
|
||||
.order_by(ExecutionJob.id.asc())
|
||||
.limit(batch)
|
||||
.all()
|
||||
)
|
||||
]
|
||||
if job_ids:
|
||||
deleted_execution_jobs = int(
|
||||
db.query(ExecutionJob)
|
||||
.filter(ExecutionJob.id.in_(job_ids))
|
||||
.delete(synchronize_session=False)
|
||||
or 0
|
||||
)
|
||||
batches += 1
|
||||
db.commit()
|
||||
|
||||
# 注意措辞:这只说明「批次预算用光了」,**不等于**「确实还有积压」——
|
||||
# 预算在上一档用完时,下一档根本没轮到执行,这里无法区分「没得删」和「没轮到」。
|
||||
# 所以做成提示而非结论,措辞上也别谎称「仍有积压」。
|
||||
@@ -224,6 +271,8 @@ def run_douyu_tasks_retention(db: Session, job: AutomationJob) -> dict[str, Any]
|
||||
"deleted": total_deleted,
|
||||
"deleted_noise": per_pass.get("noise", 0),
|
||||
"deleted_rest": per_pass.get("rest", 0),
|
||||
"deleted_execution_events": deleted_execution_events,
|
||||
"deleted_execution_jobs": deleted_execution_jobs,
|
||||
"batches": batches,
|
||||
"noise_days": noise_days,
|
||||
"business_days": business_days,
|
||||
|
||||
Reference in New Issue
Block a user