27 lines
910 B
Python
27 lines
910 B
Python
"""审计日志保留定时任务(P1-3 · Dramatiq actor,cron 每日调用)。
|
||
|
||
复用 `purge_audit_logs` management command(默认保留 180 天、分批删、
|
||
`--yes` 防手滑),与 `apps/billing/tasks.py` / `apps/notify/tasks.py`
|
||
同一范式:业务函数可直接单测,actor 只做薄包装。
|
||
"""
|
||
|
||
|
||
def purge_expired_audit_logs(days: int = 180) -> str:
|
||
"""删除早于保留窗口的审计日志,返回 command 回执。"""
|
||
from django.core.management import call_command
|
||
|
||
return call_command("purge_audit_logs", days=days, yes=True)
|
||
|
||
|
||
try:
|
||
import dramatiq
|
||
|
||
purge_expired_audit_logs_actor = dramatiq.actor(
|
||
purge_expired_audit_logs,
|
||
actor_name="purge_expired_audit_logs",
|
||
max_retries=1,
|
||
time_limit=600_000,
|
||
)
|
||
except ImportError: # pragma: no cover —— 未装 dramatiq 的精简环境
|
||
purge_expired_audit_logs_actor = None
|