- How do I install spatie/laravel-failed-job-monitor for Laravel 9+?
- Run `composer require spatie/laravel-failed-job-monitor` and publish the config with `php artisan vendor:publish --tag=failed-job-monitor-config`. Ensure your `.env` includes `FAILED_JOB_MONITOR_ENABLED=true` and configure channels like `FAILED_JOB_CHANNELS=mail,slack`. Guzzle is only needed for Slack support.
- Does this package work with Laravel Horizon?
- Yes, it integrates with Horizon and includes Horizon-specific features like job links in emails. If you’re not using Horizon, you can still use the package, but you may need to customize templates or disable Horizon-related features in the config.
- Can I filter which failed jobs trigger notifications?
- Absolutely. Use the `notificationFilter` in the config to define a closure or class-based filter. For example, exclude specific job classes or only notify after 3 failed attempts. Note that closures break with `config:cache`, so a class-based approach is recommended for production.
- What Laravel and PHP versions are supported?
- The package requires PHP 8.0+ and Laravel 5.5+ (or newer). For Laravel 9+, use version 4.x of this package. Check the [README](https://github.com/spatie/laravel-failed-job-monitor) for version-specific installation instructions.
- How do I test this package in a staging environment?
- Simulate job failures by manually failing a queued job in staging (e.g., using `Job::fail()` in a test job). Verify notifications are sent to the configured channels. Test edge cases like malformed Slack webhooks or high-volume failures to ensure reliability.
- Is there a way to disable notifications in local development?
- Yes, set `FAILED_JOB_MONITOR_ENABLED=false` in your `.env` file. For stricter control, enforce this via CI/CD pipelines or use environment-specific config files to prevent accidental notifications in local environments.
- Can I use custom notification channels (e.g., PagerDuty, SMS)?
- Yes, the package leverages Laravel’s notification system, so you can extend it to support any channel. Define a custom `Notifiable` class or use Laravel’s existing channels like SMS or HTTP. The `notifiable` config key lets you specify which class handles notifications.
- Will this package slow down my queue processing?
- No, the package is event-driven and doesn’t poll for failures. It hooks into Laravel’s failed job event, so the overhead is minimal. For high-volume queues, benchmark in staging to confirm, but the impact is typically negligible compared to the queue driver itself.
- How do I configure Slack notifications securely?
- Store your Slack webhook URL in the `.env` file as `FAILED_JOB_SLACK_WEBHOOK_URL`. Never hardcode sensitive tokens in config files. Restrict access to the webhook URL using Slack’s incoming webhook settings, and validate the URL in your CI/CD pipeline.
- What happens if I’m using a custom queue driver or non-database queue?
- The package works with all Laravel queue drivers (sync, database, Redis, etc.). It relies on Laravel’s native `failed` event for queue jobs, so as long as your driver supports this event, the package will function. No additional setup is required for Redis or other drivers.