chore: update core to v1.1.0 (hooks plugin system)

This commit is contained in:
Du Wenbo
2026-04-04 18:32:56 +08:00
6 changed files with 265 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.models.quota import EnergyQuota, QuotaUsage
from app.models.alarm import AlarmEvent
from app.models.energy import EnergyDailySummary
from app.hooks import get_hooks
logger = logging.getLogger("quota_checker")
@@ -34,6 +35,7 @@ async def check_quotas(session: AsyncSession):
)
quotas = result.scalars().all()
hooks = get_hooks()
for quota in quotas:
period_start, period_end = _get_period_range(quota.period, now)
@@ -121,4 +123,10 @@ async def check_quotas(session: AsyncSession):
f"quota={quota.quota_value:.1f} rate={usage_rate_pct:.1f}%"
)
# Customer hook: on_quota_exceeded
try:
await hooks.on_quota_exceeded(quota, usage_record, session)
except Exception as _he:
logger.error(f"Hook on_quota_exceeded error: {_he}")
await session.flush()