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.
artisan schedule), making it a seamless fit for Laravel applications. It leverages Laravel’s Eloquent models, queues, and command structure, ensuring minimal architectural disruption.monitorName(), graceTimeInMinutes()), allowing TPMs to adapt it to specific use cases without forking the package.Schedule facade and job lifecycle. Existing scheduled tasks continue to work unchanged.MonitoredScheduledTask, MonitoredScheduledTaskLogItem) and a single queue job (PingOhDearJob), with no external dependencies beyond Laravel itself and Oh Dear (optional).delete_log_items_older_than_days). Requires proactive pruning (e.g., daily model:prune command) to avoid performance degradation in high-volume environments.spatie/laravel-multitenancy, the PingOhDearJob must be explicitly whitelisted in not_tenant_aware_jobs to avoid tenant context errors.storeOutputInDb) be enabled for all tasks or only critical ones?artisan schedule), queue workers, and Eloquent ORM. No additional infrastructure (e.g., Kubernetes, Docker) is required beyond a standard Laravel deployment.PingOhDearJob. Recommends a dedicated queue for Oh Dear pings to avoid contention.schedule-monitor:sync) should be triggered post-deploy to ensure Oh Dear and local logs are up to date.schedule-monitor:list and schedule-monitor:verify commands.doNotMonitor() for tasks where observability is already handled (e.g., by third-party tools).OH_DEAR_DEBUG_LOGGING flag in staging to debug connectivity issues.PingOhDearJob is compatible with the driver’s retry logic.spatie/laravel-multitenancy via config. For other multitenancy solutions (e.g., Stancl/Tenant), manual tenant context handling may be needed.app/Console/Kernel.php to identify naming conventions and grace time requirements.app/Console/Kernel.php (e.g., daily model:prune).schedule-monitor:sync in staging and verify with schedule-monitor:list.schedule-monitor:verify.schedule-monitor:sync to deployment scripts.model:prune).Kernel.php require a sync to update Oh Dear and local logs.delete_log_items_older_than_days (default: 30).PingOhDearJob should use a dedicated queue to avoid delays during peak traffic.schedule-monitor:list) may slow down with large log tables. Indexes on task_name and created_at are recommended.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database connection issues | Logs not recorded; Oh Dear pings fail. | Retry logic in PingOhDearJob; monitor queue failures. |
| Oh Dear API downtime | Alerts delayed or lost. | Configure retry_delay_ms and retry_job_for_minutes; use local alerts as backup. |
| Log table corruption | Incomplete monitoring data. | Regular database backups; test migrations in staging. |
| Misconfigured grace time | False positives/negatives in alerts. | Validate grace times in staging; use `schedule-monitor: |
How can I help you explore Laravel packages today?