zackaj/laravel-debounce
Debounce Laravel jobs, notifications, and (Laravel 11+) artisan commands to prevent spam and reduce queue load. Uses unique locks and caching to delay execution until activity stops. Tracks each request occurrence with reports including IP and authenticated user.
Artisan::call() improvements).DebounceJob, DebounceNotification, DebounceCommand) for advanced features.debounce:command Artisan command for Laravel 11+, enabling ad-hoc debouncing of CLI tasks.after() hooks may execute before queue dispatch if sendNow=false and the debounceable implements ShouldQueue. Clarity in documentation is needed.LARAVEL_DEBOUNCE_ENABLED=false is critical for CI/CD but must be explicitly managed in test environments.Cache Strategy:
Performance:
Error Handling:
before()/after() hooks be logged or retried?Migration Path:
Observability:
php artisan queue:work). Scaling workers may be needed for high-volume debounced tasks.Assessment Phase:
Pilot Integration:
Debounce::job(new SendWelcomeEmail(), delay: 30, uniqueKey: $user->id);
Advanced Features:
DebounceJob, etc.) for custom timestamps, hooks, or report tracking.class ProcessPayment extends DebounceJob {
public function getLastActivityTimestamp(): ?Carbon {
return $this->payment->last_attempt_at;
}
}
CLI Debouncing (Laravel 11+):
php artisan calls with debounced versions:
php artisan debounce:command 60 user:export --format=csv
Configuration:
config/debounce.php (e.g., disable debouncing in staging):
LARAVEL_DEBOUNCE_ENABLED=false
Development:
composer require zackaj/laravel-debounce.php artisan vendor:publish --tag=laravel-debounce-config.LARAVEL_DEBOUNCE_ENABLED=false for immediate execution.Staging:
LARAVEL_DEBOUNCE_ENABLED=true).Production:
config/debounce.php or environment variables.before()/after() hook execution for troubleshooting.cache.ttl or switch to Redis for production.after() hook behavior clearly for developers.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache driver failure | Debouncing stops; tasks execute immediately. | Use Redis with failover; monitor cache health. |
| Queue worker crashes | Debounced tasks pile up. | Implement health checks; auto-restart workers. |
| Unique key collisions | Multiple instances execute. | Use composite keys (e.g., user_id + action). |
| Cache flushed | Report data lost. | Backup reports to DB periodically. |
after() hook errors |
Task completes but side effects fail. | Wrap hooks in try-catch; log errors. |
| Laravel upgrade incompatibility | Package breaks. | Test upgrades in staging; pin versions if needed. |
How can I help you explore Laravel packages today?