25 lines
868 B
Python
25 lines
868 B
Python
"""预警调度任务 actors(Dramatiq)。"""
|
||
|
||
import dramatiq
|
||
|
||
from apps.core.models import Tenant
|
||
from . import services as notify_services
|
||
|
||
|
||
@dramatiq.actor(max_retries=3, time_limit=300_000)
|
||
def run_alert_checks_for_tenant(tenant_id: int):
|
||
"""单租户业务预警扫描(库存低限 + 应收逾期)。"""
|
||
tenant = Tenant.objects.get(pk=tenant_id, is_active=True)
|
||
result = notify_services.run_all_alert_checks(tenant)
|
||
return result
|
||
|
||
|
||
@dramatiq.actor(max_retries=3, time_limit=600_000)
|
||
def run_all_alert_checks_for_all_tenants():
|
||
"""遍历全部活跃租户执行业务预警扫描(由 crontab 每日 08:00 触发)。"""
|
||
summary = []
|
||
for tenant in Tenant.objects.filter(is_active=True):
|
||
result = notify_services.run_all_alert_checks(tenant)
|
||
summary.append({"tenant": tenant.code, **result})
|
||
return summary
|