Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Failed Job Monitor Laravel Package

spatie/laravel-failed-job-monitor

Laravel package that notifies you when queued jobs fail. Uses Laravel’s notification system and supports email and Slack out of the box, with configurable notifiables and custom notification classes for your own alerting needs.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Observability Integration: Fits seamlessly into Laravel’s native queue system (e.g., Illuminate\Queue\Jobs\Job) and leverages Laravel’s Notification system, making it a low-friction addition for observability.
  • Event-Driven: Passively monitors job failures without requiring explicit instrumentation in job classes, reducing boilerplate.
  • Extensibility: Supports custom notification classes and notifiables, allowing alignment with existing alerting pipelines (e.g., PagerDuty, custom webhooks).
  • Horizon Compatibility: Works with Laravel Horizon (via Horizon-specific links in notifications), enhancing debugging for teams using it.

Integration Feasibility

  • Minimal Setup: Requires only composer require + config publish, with no database migrations or schema changes.
  • Dependency Alignment: Requires PHP 8+ and Laravel 8+, but supports up to Laravel 13 (as of v4.4.0). Risk: If using an older Laravel version, downgrade to v3.x (e.g., for Laravel 6.x).
  • Queue Drivers: Works with all Laravel queue drivers (database, Redis, SQS, etc.), but Slack notifications require Guzzle (guzzlehttp/guzzle).
  • Environment Variables: Supports .env-based configuration for channels/recipients (e.g., FAILED_JOB_SLACK_WEBHOOK_URL), improving security and flexibility.

Technical Risk

  • Notification Filtering: Closures in notificationFilter are not serializable (breaks config:cache). Mitigation: Use a static class method (documented in README).
  • Horizon-Specific Features: Links to Horizon’s job dashboard may break if Horizon is not used. Workaround: Customize the notification class to hide links when Horizon is absent.
  • Performance Impact: Minimal overhead during job execution, but notification delivery (e.g., Slack API calls) could introduce latency if jobs fail en masse. Mitigation: Rate-limit notifications or use a queue for alerts.
  • Customization Complexity: Extending the default notification/notifiable requires understanding Laravel’s notification system. Risk: Misconfiguration could lead to silent failures.

Key Questions

  1. Alert Volume: How frequently do jobs fail in production? Will notifications overwhelm teams? (Consider filtering or throttling.)
  2. Notification Channels: Are Slack/Mail sufficient, or are other channels (e.g., SMS, PagerDuty) needed? (Extend the notifiable class.)
  3. Horizon Dependency: Is Horizon used? If not, customize notifications to avoid broken links.
  4. Configuration Management: Will .env-based config suffice, or are dynamic recipients/channels needed? (Use environment variables or a custom notifiable.)
  5. Testing: How will failed-job scenarios be tested? (Mock notifications or use a test Slack/Mail service.)

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for Laravel’s queue system and notifications. Best for: Teams already using Laravel’s queue workers (e.g., php artisan queue:work or Horizon).
  • Queue Drivers: Compatible with all drivers, but database queues may require additional tuning if job failures are frequent (risk of locking).
  • Monitoring Stack: Integrates with existing alerting (e.g., Slack channels, email inboxes). Extension Point: Replace the default notifiable with one that forwards to Datadog/PagerDuty.
  • PHP Version: Hard Requirement: PHP 8+. Action: Upgrade if using PHP 7.x (or use v3.x for Laravel 6.x).

Migration Path

  1. Pre-Installation:
    • Verify Laravel/PHP version compatibility (see release notes).
    • Audit existing job classes for critical failures that might need filtering (e.g., transient errors like rate limits).
  2. Installation:
    composer require spatie/laravel-failed-job-monitor guzzlehttp/guzzle
    php artisan vendor:publish --tag=failed-job-monitor-config
    
  3. Configuration:
    • Set FAILED_JOB_SLACK_WEBHOOK_URL (if using Slack) and mail.to in .env.
    • Customize config/failed-job-monitor.php for channels/recipients.
  4. Testing:
    • Force a job failure in staging and verify notifications arrive.
    • Test the notificationFilter if filtering is needed (e.g., ignore JobWasTooBigException).
  5. Rollout:
    • Deploy to production and monitor notification volume for the first 24 hours.

Compatibility

  • Backward Compatibility: Breaking changes in v4.0.0 (PHP 8+, Laravel 8+). Action: Use v3.x for older stacks.
  • Horizon: Adds Horizon-specific links. Action: Customize the notification class to hide links if Horizon is unused.
  • Queue Workers: Works with all workers (e.g., queue:work, queue:listen, Horizon). Note: Supervisor/Foreman configs unchanged.
  • Third-Party Packages: No known conflicts, but test with packages that modify job execution (e.g., spatie/laravel-activitylog).

Sequencing

  1. Phase 1: Install and configure for a non-critical queue (e.g., low-priority jobs).
  2. Phase 2: Gradually enable for higher-priority queues, adjusting notificationFilter as needed.
  3. Phase 3: Extend to custom channels (e.g., PagerDuty) if Slack/Mail are insufficient.
  4. Phase 4: Integrate with incident management tools (e.g., link notifications to Jira tickets).

Operational Impact

Maintenance

  • Configuration Drift: Minimal risk if using .env for sensitive data (e.g., Slack webhooks). Action: Document config changes.
  • Updates: Regularly check for Laravel version support (e.g., v4.3.6 added Laravel 13 support). Strategy: Pin to a minor version (e.g., ^4.3) to avoid surprises.
  • Custom Code: Extending the notification/notifiable requires maintenance if Laravel updates break compatibility. Mitigation: Test custom classes against new Spatie releases.

Support

  • Debugging: Notifications include job payloads and exceptions, reducing MTTR for queue issues. Action: Document how to read failure details in alerts.
  • False Positives: Transient failures (e.g., network blips) may trigger alerts. Mitigation: Implement filtering (e.g., ignore ConnectionException).
  • Slack/Mail Delays: API rate limits or SMTP issues could delay notifications. Mitigation: Monitor delivery success rates.

Scaling

  • Notification Volume: High failure rates could flood channels. Mitigation:
    • Throttle notifications (e.g., batch failures by job class).
    • Use a separate Slack channel for critical jobs only.
  • Performance: Minimal impact on job execution, but notification delivery (e.g., Slack API calls) could add latency. Mitigation: Offload notifications to a separate queue.
  • Horizon Scaling: If using Horizon, ensure its Redis/database can handle increased job failure logging.

Failure Modes

Failure Scenario Impact Mitigation
Slack webhook URL misconfigured No alerts delivered Validate .env and test with a dummy job.
Mail server down Email alerts fail Use a fallback channel (e.g., SMS).
Database queue locks Failed jobs pile up Monitor queue length; adjust failed_jobs table size.
Custom notification class breaks No alerts, silent failures Test custom classes in staging.
config:cache with closure filter Application crashes Use a static class method for filtering.

Ramp-Up

  • Developer Onboarding:
    • Document how to trigger test failures (e.g., throw new Exception('test') in a job).
    • Show how to read failure details in notifications (e.g., job payload, exception trace).
  • Operations Onboarding:
    • Train teams on how to act on alerts (e.g., "If you see QueueOverflowException, scale workers").
    • Document the notificationFilter for future customization.
  • Incident Response:
    • Create a runbook for common job failure patterns (e.g., "If StorageException appears, check S3 permissions").
    • Integrate with incident management tools (e.g., auto-create Jira tickets from Slack alerts).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport