- How do I debounce a Laravel job to prevent duplicate queue processing?
- Extend the `DebounceJob` class in your job and use the `debounce()` facade or method to set a delay (e.g., `Debounce::job($job, 10)`). The package ensures only one instance runs within the interval using atomic locks and caching.
- Does this package work with Laravel notifications?
- Yes, extend the `DebounceNotification` class and use the `debounce()` method to delay notifications. It tracks occurrences and prevents spamming users with repeated alerts.
- What Laravel versions are supported, and is CLI debouncing available?
- The package supports Laravel 11+ for all features, including CLI debouncing for Artisan commands. For Laravel <11, only jobs and notifications are supported.
- How does report tracking work, and can I access historical data?
- Report tracking logs every occurrence with IP, user, and metadata in the cache. Use `Debounce::report()` to retrieve data, but note cache flushes will clear historical records.
- What cache driver is recommended for production?
- Redis is recommended for atomic locks and performance. Database drivers work but may introduce latency. Ensure your cache driver is configured in Laravel’s `.env` file.
- Can I customize the debounce interval dynamically?
- Yes, pass a custom delay (in seconds) to `debounce()` or override the default via configuration. For dynamic intervals, use the `overrideTimestamp()` method.
- How do I disable debouncing for testing or CI/CD?
- Set the environment variable `LARAVEL_DEBOUNCE_ENABLED=false` to bypass debouncing entirely. This is useful for testing or when immediate execution is required.
- Are there alternatives to this package for debouncing Laravel jobs?
- Alternatives include custom queue listeners or packages like `spatie/laravel-queue-scheduler`, but this package offers built-in reporting, hooks, and CLI support for Laravel 11+.
- How do I debounce an Artisan command in Laravel 11+?
- Extend `DebounceCommand` and use the `debounce()` method in your command’s logic. The package provides a `debounce:command` Artisan command for ad-hoc debouncing.
- What happens if the cache fails during debouncing?
- If the cache driver fails, atomic locks may not work, leading to potential duplicate executions. Monitor cache health and consider fallback strategies like database locks for critical tasks.