quota-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
Quota Management
配额管理
Overview
概述
Patterns for tracking and enforcing resource quotas across rate-limited services. This skill provides the infrastructure that other plugins use for consistent quota handling.
针对限流服务的资源配额跟踪与执行模式。该Skill为其他插件提供一致的配额处理基础设施。
When To Use
适用场景
- Building integrations with rate-limited APIs
- Need to track usage across sessions
- Want graceful degradation when limits approached
- Require cost estimation before operations
- 构建与限流API的集成
- 需要跨会话跟踪使用情况
- 希望在接近限制时实现优雅降级
- 操作前需要进行成本估算
When NOT To Use
不适用场景
- Project doesn't use the leyline infrastructure patterns
- Simple scripts without service architecture needs
- 项目未采用leyline基础设施模式
- 无服务架构需求的简单脚本
Core Concepts
核心概念
Quota Thresholds
配额阈值
Three-tier threshold system for proactive management:
| Level | Usage | Action |
|---|---|---|
| Healthy | <80% | Proceed normally |
| Warning | 80-95% | Alert, consider batching |
| Critical | >95% | Defer non-urgent, use secondary services |
用于主动管理的三级阈值系统:
| 级别 | 使用情况 | 操作 |
|---|---|---|
| 健康 | <80% | 正常执行 |
| 警告 | 80-95% | 发出警报,考虑批量处理 |
| 严重 | >95% | 延迟非紧急任务,使用备用服务 |
Quota Types
配额类型
python
@dataclass
class QuotaConfig:
requests_per_minute: int = 60
requests_per_day: int = 1000
tokens_per_minute: int = 100000
tokens_per_day: int = 1000000python
@dataclass
class QuotaConfig:
requests_per_minute: int = 60
requests_per_day: int = 1000
tokens_per_minute: int = 100000
tokens_per_day: int = 1000000Quick Start
快速开始
Check Quota Status
检查配额状态
python
from leyline.quota_tracker import QuotaTracker
tracker = QuotaTracker(service="my-service")
status, warnings = tracker.get_quota_status()
if status == "CRITICAL":
# Defer or use secondary service
passpython
from leyline.quota_tracker import QuotaTracker
tracker = QuotaTracker(service="my-service")
status, warnings = tracker.get_quota_status()
if status == "CRITICAL":
# Defer or use secondary service
passRecord Usage
记录使用情况
python
tracker.record_request(
tokens=estimated_tokens,
success=True,
duration=elapsed_seconds
)python
tracker.record_request(
tokens=estimated_tokens,
success=True,
duration=elapsed_seconds
)Estimate Before Execution
执行前估算
python
can_proceed, issues = tracker.can_handle_task(estimated_tokens)
if not can_proceed:
print(f"Quota issues: {issues}")python
can_proceed, issues = tracker.can_handle_task(estimated_tokens)
if not can_proceed:
print(f"Quota issues: {issues}")Integration Pattern
集成模式
Other plugins reference this skill:
yaml
undefined其他插件可引用该Skill:
yaml
undefinedIn your skill's frontmatter
In your skill's frontmatter
dependencies: [leyline:quota-management]
Then use the shared patterns:
1. Initialize tracker for your service
2. Check quota before operations
3. Record usage after operations
4. Handle threshold warnings gracefullydependencies: [leyline:quota-management]
然后使用共享模式:
1. 为你的服务初始化跟踪器
2. 操作前检查配额
3. 操作后记录使用情况
4. 妥善处理阈值警告Detailed Resources
详细资源
- Threshold Strategies: See for degradation patterns
modules/threshold-strategies.md - Estimation Patterns: See for token/cost estimation
modules/estimation-patterns.md
- 阈值策略:查看了解降级模式
modules/threshold-strategies.md - 估算模式:查看了解令牌/成本估算
modules/estimation-patterns.md
Exit Criteria
退出标准
- Quota status checked before operation
- Usage recorded after operation
- Threshold warnings handled appropriately
- 操作前已检查配额状态
- 操作后已记录使用情况
- 已妥善处理阈值警告