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 Schedule Monitor Laravel Package

spatie/laravel-schedule-monitor

Monitor Laravel scheduled tasks by logging each run’s start, finish, failure, or skip to the database. Use an Artisan list command to see execution history and spot issues. Optional Oh Dear sync alerts you when tasks fail or don’t run on time.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: The package is designed specifically for Laravel’s built-in task scheduling system (artisan schedule), making it a seamless fit for Laravel applications. It leverages Laravel’s Eloquent ORM, command bus, and queue systems, ensuring compatibility with Laravel’s architecture.
  • Modular Design: The package follows a modular approach with configurable models (MonitoredScheduledTask, MonitoredScheduledTaskLogItem), allowing customization for specific use cases (e.g., multitenancy, custom storage).
  • Extensibility: Supports customization via method chaining (e.g., monitorName(), graceTimeInMinutes(), storeOutputInDb()), enabling granular control over monitoring behavior without modifying core logic.
  • Event-Driven: Passively logs task execution lifecycle events (start, end, failure, skip) without requiring manual instrumentation, reducing development overhead.

Integration Feasibility

  • Low Friction: Installation and setup are straightforward (composer install, publish migrations/config, run migrations). The package requires minimal changes to existing app/Console/Kernel.php (e.g., adding schedule-monitor:sync to deployment scripts).
  • Database Agnostic: Works with any database supported by Laravel, though performance may vary based on log retention policies (e.g., pruning old entries).
  • Queue Dependency: Oh Dear integration relies on Laravel’s queue system, which may require additional infrastructure (e.g., Redis, database queue) if not already in place. This is a critical dependency for real-time monitoring.
  • Laravel Version Support: Actively maintained for Laravel 10/11, with backward compatibility for Laravel 8 (via v2). No breaking changes expected for current LTS versions.

Technical Risk

  • Queue Reliability: Oh Dear pings are dispatched as queued jobs (PingOhDearJob). If the queue fails (e.g., misconfigured, overloaded), notifications may be delayed or lost. Mitigation: Monitor queue health and implement retries/alerts.
  • Log Bloat: Unpruned logs can grow unbounded, impacting database performance. Mitigation: Configure delete_log_items_older_than_days and use Laravel’s pruning feature (as documented).
  • Multitenancy Edge Cases: Oh Dear pings are tenant-agnostic by default. In multitenant apps, ensure PingOhDearJob is added to not_tenant_aware_jobs to avoid failures.
  • Grace Time Misconfiguration: Incorrect graceTimeInMinutes values may lead to false positives/negatives in monitoring. Validate with schedule-monitor:verify.
  • Third-Party Dependency: Oh Dear integration introduces a dependency on an external service. Downtime or API changes could disrupt monitoring. Mitigation: Use the package’s standalone features (DB logging) as a fallback.

Key Questions

  1. Queue Infrastructure: Is the application already using Laravel queues (e.g., Redis, database)? If not, what are the plans to implement one for Oh Dear pings?
  2. Log Retention Policy: How long should execution logs be retained? Is the default 30 days sufficient, or does the team need custom pruning logic?
  3. Alerting Strategy: Beyond Oh Dear, are there additional alerting mechanisms (e.g., Slack, PagerDuty) for critical task failures?
  4. Multitenancy: Is the application multitenant? If so, is spatie/laravel-multitenancy in use, and has PingOhDearJob been whitelisted?
  5. Performance Impact: For high-frequency tasks (e.g., every minute), will logging overhead affect performance? Should doNotMonitor() be used for non-critical tasks?
  6. Deployment Workflow: Is schedule-monitor:sync integrated into CI/CD pipelines? How will sync conflicts (e.g., renamed tasks) be handled?
  7. Standalone vs. Oh Dear: Will the team rely solely on Oh Dear for alerts, or is the DB logging layer a primary source of truth for auditing?

Integration Approach

Stack Fit

  • Core Laravel Stack: Fully compatible with Laravel’s scheduling system, Eloquent, and queues. No additional PHP extensions or libraries required.
  • Database: Works with MySQL, PostgreSQL, SQLite, and SQL Server. Log table schema is simple (no complex joins or indexes by default).
  • Queue Systems: Supports all Laravel queue drivers (database, Redis, beanstalkd, etc.). Oh Dear pings are dispatched asynchronously to avoid blocking task execution.
  • Monitoring Tools: Integrates with Oh Dear for alerting, but logs are stored in the application’s database, enabling custom queries or integrations with tools like Datadog, Prometheus, or Laravel Nova.
  • Multitenancy: Explicit support for spatie/laravel-multitenancy via config. For other multitenancy setups, manual tenant context handling may be required for PingOhDearJob.

Migration Path

  1. Assessment Phase:
    • Audit existing scheduled tasks in app/Console/Kernel.php to identify candidates for monitoring (exclude non-critical or high-frequency tasks if needed).
    • Review current logging/alerting mechanisms to avoid duplication (e.g., if tasks already log to a third-party tool).
  2. Pilot Integration:
    • Install the package in a staging environment and test with a subset of tasks.
    • Verify schedule-monitor:sync and schedule-monitor:list output matches expectations.
    • Configure Oh Dear integration (if desired) and validate alerts.
  3. Gradual Rollout:
    • Start with non-critical tasks, then expand to critical paths.
    • Use doNotMonitor() for tasks where logging is unnecessary (e.g., health checks).
  4. Production Deployment:
    • Add schedule-monitor:sync to deployment scripts (e.g., post-deploy hook).
    • Set up a daily pruning job for log cleanup.
    • Configure monitoring for the PingOhDearJob queue (e.g., Horizon, Laravel Telescope).

Compatibility

  • Laravel Versions: Tested on Laravel 10/11; v2 supports Laravel 8. No conflicts with Laravel’s core or popular packages (e.g., Laravel Horizon, Laravel Nova).
  • PHP Versions: Requires PHP 8.1+ (Laravel 10/11 baseline). No additional PHP extensions needed.
  • Task Types: Supports commands, closures, jobs, and anonymous functions. Custom naming is required for closures without explicit classes.
  • Customization: Models and config are publishable, allowing overrides for storage engines, log formats, or business logic (e.g., custom pruning).

Sequencing

  1. Prerequisites:
    • Ensure Laravel queues are configured and functional (critical for Oh Dear integration).
    • Set up database backups before running migrations.
  2. Installation Order:
    • Composer install → Publish migrations/config → Run migrations → Configure Kernel.php.
  3. Post-Installation:
    • Run schedule-monitor:sync immediately after deployment.
    • Set up pruning (e.g., daily model:prune command).
    • Configure Oh Dear (if used) and verify with schedule-monitor:verify.
  4. Ongoing:
    • Monitor queue health for PingOhDearJob.
    • Review logs periodically for anomalies (e.g., skipped tasks, failures).

Operational Impact

Maintenance

  • Low Maintenance Overhead:
    • No manual logging required; events are auto-captured.
    • Pruning is automated via Laravel’s model pruning feature.
  • Configuration Drift:
    • Task names or grace times must be updated manually in Kernel.php if schedules change. Consider a script to auto-sync these from a central config.
  • Dependency Updates:
    • Monitor Spatie’s release notes for breaking changes (e.g., Laravel version drops). Oh Dear API changes may require config updates.
  • Log Retention:
    • Default 30-day retention may need adjustment based on compliance or debugging needs. Custom pruning logic can be added.

Support

  • Troubleshooting:
    • Use schedule-monitor:list to diagnose missed/failed tasks.
    • Enable OH_DEAR_DEBUG_LOGGING for connectivity issues with Oh Dear.
    • Check monitored_scheduled_task_log_items for execution details (e.g., memory usage, duration).
  • Alert Fatigue:
    • Oh Dear alerts may trigger frequently for tasks with tight grace times. Adjust graceTimeInMinutes or use doNotMonitor for non-critical tasks.
  • False Positives/Negatives:
    • Network issues or queue delays may cause false alerts. Monitor queue metrics (e.g., Horizon) to correlate with Oh Dear pings.

Scaling

  • Log Volume:
    • High-frequency tasks (e.g., every minute) can generate large log volumes. Consider:
      • Increasing delete_log_items_older_than_days.
      • Archiving logs to cold storage (e.g., S3) for long-term retention.
      • Using doNotMonitor() for non-critical tasks.
  • Queue Scaling:
    • Oh Dear pings are queued; ensure the queue can handle spikes (e.g., Redis cluster, dedicated queue workers).
    • For large-scale apps, consider a dedicated
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