My backup job failed at 3 AM last month. I found out on Monday when a client asked why their data wasn't updated.
This kept happening. Sync tasks stuck for hours. Report generation failing silently. No notifications, no logs I could easily check.
So I built something to fix it.
What I built
Laravel Smart Scheduler tracks every scheduled task execution automatically. Install it, and you get:
- Execution history for every task
- Stuck task detection (when server crashes mid-task)
- Email notifications on failure
- Overlap prevention with visibility
composer require jiordiviera/laravel-smart-scheduler
php artisan vendor:publish --tag=smart-scheduler-migrations
php artisan migrate
No changes to your existing tasks. It hooks into Laravel's events.
How it works
Every execution gets recorded:
use Jiordiviera\SmartScheduler\LaravelSmartScheduler\Models\ScheduleRun;
// Recent executions
$runs = ScheduleRun::latest('started_at')->limit(10)->get();
// What failed
$failed = ScheduleRun::where('status', ScheduleRun::STATUS_FAILED)->get();
Each record has: task identifier, status, start/end time, duration, output, exception message, server name.
Stuck task detection
This is the feature I needed most.
When your server crashes or a process gets killed, the task stays in "starting" status. Next run sees an overlap and skips. Your task never runs again until you manually fix it.
Smart Scheduler detects this:
// config/smart-scheduler.php
'stuck_timeout_minutes' => 60,
When a new execution starts, it checks for old "starting" tasks past the timeout, marks them as "stuck", notifies you, and lets the new execution proceed.
You can also run it manually:
php artisan smart-scheduler:detect-stuck
Notifications
// config/smart-scheduler.php
'notifications' => [
'email' => [
'recipients' => ['admin@example.com'],
],
'notify_on_stuck' => true,
],
Or in your .env:
SMART_SCHEDULER_EMAIL_RECIPIENTS=admin@example.com
Setup I recommend
// routes/console.php
use Illuminate\Support\Facades\Schedule;
// Clean old records weekly
Schedule::command('smart-scheduler:purge')->weekly();
// Detect stuck tasks every 30 minutes
Schedule::command('smart-scheduler:detect-stuck')->everyThirtyMinutes();
Custom notifications
Want Slack instead of email? Implement the interface:
use Jiordiviera\SmartScheduler\LaravelSmartScheduler\Contracts\SmartNotifierInterface;
class SlackNotifier implements SmartNotifierInterface
{
public function sendFailureNotification(ScheduleRun $run): void
{
// Your Slack logic
}
public function sendStuckNotification(ScheduleRun $run): void
{
// Your Slack logic
}
}
// In a service provider
$this->app->singleton(SmartNotifierInterface::class, SlackNotifier::class);
Requirements
- PHP 8.2+
- Laravel 11 or 12
Links
- GitHub: jiordiviera/laravel-smart-scheduler
- Packagist: jiordiviera/laravel-smart-scheduler
If this is useful to you, a star on GitHub helps.
What do you use to monitor your scheduled tasks?
Top comments (0)