laravel maintained by observe
Observe for Laravel
Monitor every Laravel scheduled task with Observe. If a task fails, exits non-zero or misses a run, an incident opens on your monitor, and the next good run resolves it. You don't change your schedule: the package listens to the scheduler's own events.
Works with Laravel 10, 11 and 12 on PHP 8.2+. (Composer flags every Laravel 10 release with security advisories, so on Laravel 10 you may need audit.block-insecure set to false to install anything; upgrading is the better fix.)
Install in 3 steps
-
Require the package:
composer require observe/laravel -
Add your token and monitor to
.env. Create the token, with read and write access, under Profile → API & data. The monitor's Heartbeat page shows both lines with its id already filled in.OBSERVE_TOKEN=your-observe-token OBSERVE_MONITOR=your-monitor-id -
Register your tasks on every deploy:
php artisan observe:syncA task you remove from the schedule is removed from Observe on the next sync.
php artisan observe:test checks the token and monitor id. php artisan observe:list shows what observe:sync will send.
Per-task options
use Illuminate\Support\Facades\Schedule;
Schedule::command('backup:run')->dailyAt('03:00')->observe(graceMinutes: 30);
Schedule::call(fn () => Cache::flush())->hourly()->observe(name: 'flush-cache');
Schedule::command('telescope:prune')->daily()->doNotObserve();
graceMinutesis how long past the scheduled time a run can be before it counts as missed. The default is 5, orOBSERVE_GRACE_MINUTES.nameis how Observe knows the task. Without it the package uses the task's description (->name('…'), or the class name forSchedule::job()), then its command (backup:run --only-db). Two tasks with the same name get their cron expression added, e.g.reports:send [0 9 * * 1]. A closure needs a name. Without one it isn't observed, andobserve:syncwarns you.- Changing a task's name or command makes it a new task in Observe, and the old one is removed on the next sync.
What gets sent
| Scheduler event | Check-in |
|---|---|
ScheduledTaskStarting |
starting |
ScheduledTaskFinished |
finished with the runtime and exit code. A non-zero exit code counts as a failure, and the end of the task's output file is attached if it writes to one. |
ScheduledBackgroundTaskFinished |
finished for ->runInBackground() tasks, sent when the process really ends |
ScheduledTaskFailed |
failed with the exception's message |
ScheduledTaskSkipped |
skipped (a when() / skip() filter said no), so a skipped run doesn't read as missed |
Each check-in waits at most OBSERVE_TIMEOUT seconds (default 2). A failed ping is ignored, so it never fails a task, and if Observe can't be reached at all the rest of that schedule:run skips its pings instead of waiting on each one. If you want the scheduler process to make no HTTP calls at all, set OBSERVE_QUEUE to a queue connection name and the pings are sent from your queue worker instead.
If OBSERVE_TOKEN or OBSERVE_MONITOR is not set (locally, in CI), nothing is sent.
Configuration
Publishing the config is optional:
php artisan vendor:publish --tag=observe-config
| Env | Default | |
|---|---|---|
OBSERVE_TOKEN |
API token with read and write access | |
OBSERVE_MONITOR |
The monitor's id | |
OBSERVE_URL |
https://observe.live |
|
OBSERVE_GRACE_MINUTES |
5 |
|
OBSERVE_TIMEOUT |
2 |
Seconds per ping |
OBSERVE_QUEUE |
A queue connection for pings (off by default) |
Installing before the Packagist release
Until the package is on Packagist, install it from a checkout of the Observe repository with a path repository in your app's composer.json:
"repositories": [
{ "type": "path", "url": "../lookout-monitor/packages/observe-laravel", "options": { "symlink": false } }
]
composer require observe/laravel:@dev
Moving from spatie/laravel-schedule-monitor
Remove spatie/laravel-schedule-monitor and the OH_DEAR_* lines, then follow the 3 steps above. Your tasks keep their history in Observe as long as their names stay the same. Both packages name an artisan command task by its command (backup:run), so most tasks carry over; check with php artisan observe:list. The Oh Dear-compatible endpoints keep working if you would rather stay on spatie's package.
Testing
composer install
composer test
License
MIT. See LICENSE.