spatie/laravel-schedule-monitor
Monitor Laravel scheduled tasks by logging starts, finishes, failures, and skips to a database table and viewing run history via an Artisan command. Optionally sync with Oh Dear to get alerts when tasks fail or don’t run on time.
MonitoredScheduledTask models).app/Console/Kernel.php), migrations, and queues, reducing friction in adoption.monitorName() or doNotMonitor() modifiers). No changes to task logic are needed unless opting into advanced features (e.g., output storage).monitored_scheduled_tasks and monitored_scheduled_task_log_items), requiring:
task_id, event_type, and created_at for query performance.PingOhDearJob), necessitating:
retry_job_for_minutes).ohdear.app (with fallback retry logic).| Risk Area | Mitigation Strategy |
|---|---|
| Database Bloat | Configure delete_log_items_older_than_days and use Laravel’s pruning (model:prune). |
| Oh Dear API Failures | Retry logic with exponential backoff (retry_delay_ms), debug logging, and queue isolation. |
| Task Naming Ambiguity | Enforce monitorName() for critical tasks; default to class/command names. |
| Multitenancy Conflicts | Explicitly whitelist PingOhDearJob in not_tenant_aware_jobs (if using Spatie’s multitenancy). |
| Performance Overhead | Log writes are lightweight (single DB insert per event); benchmark under high task volume. |
| Sync Command Side Effects | Use --keep-old flag for non-destructive Oh Dear syncs during deployments. |
Observability Strategy:
Operational Constraints:
Deployment Workflow:
schedule-monitor:sync be automated in CI/CD (e.g., post-deploy hook) or run manually?External Dependencies:
Scaling Considerations:
app/Console/Kernel.php via method chaining (monitorName(), graceTimeInMinutes()).vendor:publish).ohdear.app.cron-job-monitoring permissions.Assessment Phase:
app/Console/Kernel.php for naming clarity and grace time needs.Pilot Deployment:
composer require spatie/laravel-schedule-monitor
php artisan vendor:publish --provider="Spatie\ScheduleMonitor\ScheduleMonitorServiceProvider" --tag="schedule-monitor-migrations"
php artisan migrate
OH_DEAR_API_TOKEN and OH_DEAR_MONITOR_ID (if using Oh Dear).php artisan schedule-monitor:sync and verify with schedule-monitor:list.Gradual Rollout:
storeOutputInDb()).Production Cutover:
schedule-monitor:sync in deployment scripts.// app/Console/Kernel.php
$schedule->command('model:prune', ['--model' => \Spatie\ScheduleMonitor\Models\MonitoredScheduledTaskLogItem::class])->daily();
PingOhDearJob to not_tenant_aware_jobs).Pre-requisites:
Installation Order:
.env.Post-Installation:
config/schedule-monitor.php for changes (e.g., grace time, log retention).schedule-monitor:verify).model:prune command runs daily (cron job or Laravel scheduler).OH_DEAR_DEBUG_LOGGING=true for diagnostics.monitorName() is used where needed.schedule-monitor:verify.monitored_scheduled_task_log_items by created_at.How can I help you explore Laravel packages today?