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

Send instant notifications when Laravel queued jobs fail. Uses Laravel’s notification system with built-in Mail and Slack support, configurable via env/config, and easy install/publish. Great for monitoring production queues and alerting the right people.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Native Laravel Integration: Leverages Laravel’s built-in queue system and notification framework, ensuring seamless compatibility with existing Laravel applications.
    • Modular Design: Decouples monitoring logic from notification delivery, allowing customization of both the notification content and recipients.
    • Extensibility: Supports custom notification classes and filter logic, enabling tailored behavior for specific use cases (e.g., prioritizing critical jobs).
    • Event-Driven: Hooks into Laravel’s job failure events, minimizing performance overhead by only triggering when jobs fail.
    • Multi-Channel Support: Out-of-the-box support for email and Slack, with room for additional channels (e.g., PagerDuty, SMS) via custom notifiable classes.
  • Cons:

    • Tight Coupling to Laravel: Not applicable for non-Laravel PHP projects (though this is expected given the package’s scope).
    • Horizon Dependency: Some features (e.g., direct links to failed jobs in Horizon) assume Laravel Horizon is used, which may not be the case in all deployments.

Integration Feasibility

  • Low Effort: Installation and basic setup require minimal changes (composer install, config publish, .env updates).
  • Queue System Agnostic: Works with any Laravel-supported queue driver (database, Redis, SQS, etc.), though performance characteristics may vary.
  • Notification System Dependency: Requires Laravel’s notification system (e.g., Illuminate\Notifications\Notifiable) to be properly configured for email/Slack.

Technical Risk

  • Minimal Risk:
    • Backward Compatibility: Actively maintained with support for Laravel 9–13 and PHP 8+. Downgrade risks are mitigated by clear versioning.
    • Configuration Overrides: Potential for conflicts if custom notification classes or filter logic are poorly implemented (e.g., breaking serialization in config:cache).
    • Horizon-Specific Features: Non-Horizon deployments may miss UI/UX enhancements (e.g., direct job links), but core functionality remains intact.
  • Mitigation:
    • Test customizations in a staging environment before production deployment.
    • Use feature flags (e.g., FAILED_JOB_MONITOR_ENABLED) to toggle monitoring during rollouts.

Key Questions

  1. Notification Prioritization:
    • How should failed jobs be prioritized (e.g., by job class, queue, or custom metadata)? The package’s notificationFilter can address this, but requires upfront design.
  2. Recipient Management:
    • Are dynamic recipient lists (e.g., based on job payload or team assignments) needed? The default config supports static lists, but custom notifiable classes can introduce dynamic logic.
  3. Alert Fatigue:
    • How will false positives (e.g., transient failures) be handled? Consider integrating with a deduplication layer or rate-limiting notifications.
  4. Compliance:
    • Are there regulatory requirements for logging failed job notifications (e.g., GDPR for email recipients)? The package does not include built-in logging, so this must be added separately.
  5. Scaling:
    • How will notification volume scale with job queue size? Slack/email APIs may throttle high-volume alerts; consider batching or sampling for non-critical jobs.
  6. Custom Metrics:
    • Should failed job metrics (e.g., failure rates, latency) be surfaced in monitoring tools (e.g., Datadog, Prometheus)? The package does not include this; integration would require custom instrumentation.

Integration Approach

Stack Fit

  • Laravel-Centric: Ideal for Laravel applications using queues (e.g., Illuminate\Queue\Queue, Illuminate\Bus\Dispatchable).
  • Queue Drivers: Compatible with all Laravel-supported drivers, but performance may vary:
    • Database: Simple but slower for high-volume queues.
    • Redis/SQS: Recommended for production due to scalability.
  • Notification Channels:
    • Email: Requires Laravel’s mail configuration (e.g., SMTP, Mailgun).
    • Slack: Requires guzzlehttp/guzzle and a Slack webhook URL.
    • Custom Channels: Extendable via custom notifiable classes (e.g., Twilio for SMS, PagerDuty for alerts).

Migration Path

  1. Pre-Integration:
    • Audit existing job failures: Identify critical jobs that must trigger alerts vs. those that can be deprioritized.
    • Design custom notification classes/filters if default behavior is insufficient.
  2. Installation:
    composer require spatie/laravel-failed-job-monitor guzzlehttp/guzzle
    php artisan vendor:publish --tag=failed-job-monitor-config
    
  3. Configuration:
    • Update .env with channels and recipients:
      FAILED_JOB_MONITOR_ENABLED=true
      FAILED_JOB_CHANNELS=mail,slack
      FAILED_JOB_EMAILS=team@example.com
      FAILED_JOB_SLACK_WEBHOOK_URL=https://hooks.slack.com/...
      
    • Customize config/failed-job-monitor.php for advanced use cases (e.g., filters, custom notifiable).
  4. Testing:
    • Simulate job failures in staging to validate notifications.
    • Test edge cases (e.g., malformed Slack webhooks, email throttling).
  5. Rollout:
    • Enable monitoring in phases (e.g., non-critical jobs first).
    • Monitor notification volume and adjust filters as needed.

Compatibility

  • Laravel Versions: Supports 9–13 (PHP 8+). Drop legacy support if using older versions.
  • Queue Workers: Works with Laravel’s queue workers (php artisan queue:work) and Horizon.
  • Third-Party Integrations:
    • Slack: Requires guzzlehttp/guzzle (included in installation).
    • Email: Relies on Laravel’s mail drivers (e.g., SMTP, SES).
    • Custom: Extend Spatie\FailedJobMonitor\Notification or Notifiable for additional channels.

Sequencing

  1. Phase 1: Basic setup (email/Slack for all failures).
  2. Phase 2: Customize notifications (e.g., job-specific templates, dynamic recipients).
  3. Phase 3: Implement filtering (e.g., ignore transient failures, prioritize critical jobs).
  4. Phase 4: Integrate with monitoring tools (e.g., log failed job metadata to a database or metrics system).

Operational Impact

Maintenance

  • Proactive:
    • Configuration Drift: Monitor .env and config file changes to ensure consistency across environments.
    • Dependency Updates: Regularly update the package to leverage bug fixes and new features (e.g., Laravel 13 support in v4.3.6).
  • Reactive:
    • Notification Failures: Implement retries or dead-letter queues for failed notifications (e.g., Slack webhook timeouts).
    • Custom Logic: Maintain custom notification classes/filters as part of the codebase.

Support

  • Troubleshooting:
    • No Notifications: Verify FAILED_JOB_MONITOR_ENABLED=true, queue workers are running, and notification channels are configured.
    • Duplicate Alerts: Check for job retries or queue redelivery (e.g., max_attempts in jobs).
    • Slack/Email Failures: Validate webhook URLs and SMTP credentials.
  • Documentation:
    • Maintain runbooks for common issues (e.g., "Failed job alert not received").
    • Document customizations (e.g., notificationFilter logic) for onboarding.

Scaling

  • Performance:
    • Notification Volume: High-volume queues may overwhelm Slack/email APIs. Mitigate with:
      • Rate-limiting (e.g., FAILED_JOB_CHANNELS=slack only for critical jobs).
      • Batching (e.g., aggregate failures by job class/hour).
    • Queue Backlog: Failed job monitoring adds minimal overhead, but ensure queue workers can handle increased load.
  • Horizontal Scaling:
    • The package is stateless; scale queue workers independently of monitoring logic.

Failure Modes

Failure Scenario Impact Mitigation
Queue worker crashes No notifications for failed jobs Use supervisor/PM2 to restart workers.
Slack webhook URL invalid Slack alerts fail silently Validate webhook URL in CI/CD.
Email SMTP misconfiguration Email alerts fail Monitor mail queue; use a fallback channel.
Custom notificationFilter error All notifications suppressed Wrap filter logic in try-catch; log errors.
Database queue corruption Failed jobs not logged Use Redis/SQS for production; monitor queue health.
High alert volume Alert fatigue, API throttling Implement sampling or prioritization rules.

Ramp-Up

  • Onboarding:
    • Developers: Document job failure handling patterns (e.g., throw new \Exception vs. `throw new \RuntimeException
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai