Quota Handling
This guide explains how TMGMT Lara Translate handles Lara API quota issues and automatic retry mechanisms.
Understanding Lara API Quotas
Quota Types
Lara API imposes several types of limits: - Character limits: Maximum characters per time period - Request limits: Maximum API calls per timeframe - Concurrent limits: Simultaneous translation requests - Plan-based limits: Based on your subscription tier
Quota Exceeded Behavior
When quota is exceeded, the Lara API returns specific error responses: - HTTP 429: Too Many Requests - Custom errors: "Quota exceeded" or "Limit reached" - Rate limiting: Temporary throttling of requests
Automatic Retry Mechanism
Symfony Messenger Retry Logic
The module handles quota errors through Symfony Messenger's built-in retry system:
// Simplified retry flow
try {
$this->processTranslation($jobItem);
} catch (LaraException $e) {
if ($this->isTransientError($e)) {
// Re-throw for automatic retry
throw $e;
}
// Permanent error - mark as failed
throw new UnrecoverableMessageHandlingException($e->getMessage());
}
Transient vs Permanent Errors
The module classifies errors for appropriate handling:
Transient Errors (Auto-Retry)
- Quota exceeded: API quota temporary limit
- Network timeout: Connection issues
- HTTP 429: Rate limiting
- HTTP 5xx: Service unavailable
- Connection refused: Temporary network problems
Permanent Errors (No Retry)
- Invalid credentials: Authentication failures
- Unsupported language: Language not available
- Invalid format: Unsupported content format
- HTTP 4xx client errors: Request format issues
Retry Configuration
Default Retry Behavior
The module uses Symfony Messenger defaults: - Exponential backoff: Increasing delay between retries - Maximum attempts: Built-in retry limit (typically 3-5 attempts) - Delay progression: 30s, 60s, 120s, 240s, etc.
Custom Retry Settings
You can configure retry behavior:
# messenger.settings (custom configuration)
transports:
async:
retry_strategy: 'exponential'
max_retries: 5
delay: 30
multiplier: 2
Monitoring Retry Status
Track how many times jobs are retried:
# Check for retry indicators in logs
drush watchdog:show --type=tmgmt_laratranslate | grep -i retry
# Count quota errors
drush watchdog:show --type=tmgmt_laratranslate | grep -i quota | wc -l
Quota Error Messages
User-Facing Messages
When quota errors occur, the module provides clear feedback:
Job Item Messages
- "Translation quota exceeded. Job item will be automatically retried when quota is available. Error: @error"
- "Rate limit reached. Translation will retry automatically."
Log Messages
- INFO: "Transient error processing job item @id: @error. Will retry."
- WARNING: "Job item @id translation failed due to quota exceeded. Item will be retried."
No Panic Messages
The module avoids alarming language: - Uses "automatic retry" instead of "error" - Provides clear next steps - Estimates retry timing
Managing Quota Limits
Proactive Monitoring
Monitor your quota usage before hitting limits:
# Check recent API usage
drush tmgmt-job:list --field=created,word_count --format=yaml
# Monitor error rates
drush watchdog:show --type=tmgmt_laratranslate --severity=warning --limit=20
Usage Patterns
Track your translation patterns: - Peak hours: When quota is most likely to be exceeded - Volume trends: Growth in translation requests - Content size: Average characters per job
Quota Planning
- Buffer time: Allow margin for unexpected requests
- Stagger submissions: Spread large jobs over time
- Off-peak processing: Schedule large translations during low-usage periods
Advanced Quota Management
Custom Rate Limiting
Implement your own rate limiting for smoother operation:
<?php
// Custom rate limiting example
class CustomRateLimiter {
private $lastRequest = 0;
private $minInterval = 2; // 2 seconds minimum
public function checkLimit() {
$now = time();
if ($now - $this->lastRequest < $this->minInterval) {
sleep($this->minInterval - ($now - $this->lastRequest));
}
$this->lastRequest = time();
}
}
?>
Queue Prioritization
When quota is limited, prioritize important translations: - Critical content: Legal pages, notices - Time-sensitive: News, announcements - High-value: Product pages, landing pages
Batch Size Optimization
Adjust job sizes to work within quota: - Small batches: More predictable usage - Regular intervals: Steady quota consumption - Buffer capacity: Keep some quota for emergencies
Troubleshooting Quota Issues
Chronic Quota Exceeded
Symptoms: Frequent quota errors, job delays
Diagnosis:
# Check frequency of quota errors
drush watchdog:show --type=tmgmt_laratranslate --limit=50 | grep -i quota | wc -l
# Check job submission patterns
drush tmgmt-job:list --field=created --format=yaml | tail -20
Solutions: 1. Upgrade your Lara plan: Higher quota limits 2. Optimize submission timing: Spread requests evenly 3. Reduce concurrent jobs: Process one at a time 4. Contact Lara support: Discuss custom limits
Stuck in Retry Loop
Symptoms: Jobs retrying endlessly without completion
Diagnosis:
# Check specific job item history
drush tmgmt-job-item:list --job=123 --format=yaml
# Look for retry patterns
drush watchdog:show --type=tmgmt_laratranslate | grep "job item 123"
Solutions: 1. Manual intervention: Pause/resume specific jobs 2. Configuration check: Verify retry limits are appropriate 3. API status: Check if Lara API has issues
Quota Confusion
Symptoms: Unexpected quota errors on small jobs
Diagnosis: - Check your Lara account dashboard for actual quota usage - Verify if other applications are using your API keys - Confirm time zone and reset times for quota periods
Best Practices
Quota-Aware Development
- Test with low quota: Develop with conservative limits
- Graceful degradation: Queue when quota low
- User feedback: Clear messaging about quota status
Operational Guidelines
- Monitor daily: Check quota usage and error rates
- Plan ahead: Schedule large jobs when quota is available
- Automate responses: Set up alerts for quota issues
- Document exceptions: Track unusual quota events
User Communication
Be transparent with users about quota: - Clear error messages: Explain what's happening - Estimated times: When translations should resume - Alternative options: Manual processing or external services
Emergency Procedures
Quota Exhaustion Recovery
When quota is completely exhausted:
- Pause new submissions: Stop queueing new translations
- Process existing jobs: Let current retries complete
- Monitor reset time: Watch for quota renewal
- Resume operations: Gradually restart new submissions
Critical Content Handling
For urgent translations during quota limits: - Alternative providers: Configure backup translators - Manual translation: Human translation for critical content - Priority requests: Contact Lara support for emergency increases
Related Documentation
- Troubleshooting Guide - General issue resolution
- Architecture Guide - Messenger retry implementation
- Monitoring Guide - Status tracking and health checks
- Configuration Guide - Provider setup options