PHPackages                             jiordiviera/laravel-smart-scheduler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jiordiviera/laravel-smart-scheduler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jiordiviera/laravel-smart-scheduler
===================================

A Laravel package for smart task scheduling

v1.1.0(5mo ago)1118MITPHPPHP ^8.2CI passing

Since Nov 3Pushed 5mo agoCompare

[ Source](https://github.com/jiordiviera/laravel-smart-scheduler)[ Packagist](https://packagist.org/packages/jiordiviera/laravel-smart-scheduler)[ RSS](/packages/jiordiviera-laravel-smart-scheduler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Laravel Smart Scheduler
=======================

[](#laravel-smart-scheduler)

[![Latest Version on Packagist](https://camo.githubusercontent.com/efdb3989806886ed74d47f3cf8795f1684260848c4331c0d300c294bd1c71469/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a696f72646976696572612f6c61726176656c2d736d6172742d7363686564756c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jiordiviera/laravel-smart-scheduler)[![GitHub Tests Action Status](https://camo.githubusercontent.com/00eadd08c91101ed95ec406b5eb87d9a53361fc66375dccbe15e9aa6dd013451/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a696f72646976696572612f6c61726176656c2d736d6172742d7363686564756c65722f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jiordiviera/laravel-smart-scheduler/actions?query=workflow%3Atests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ef960022ac5f64763158335c1bf348fa7c448760f3d92cf7d1fc15cc6a7635ea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a696f72646976696572612f6c61726176656c2d736d6172742d7363686564756c65722f70696e742e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jiordiviera/laravel-smart-scheduler/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a18b74f9786b7bd7097ffd1ff5e9b32ac4efe72168a3fed6153c63d6605e944b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a696f72646976696572612f6c61726176656c2d736d6172742d7363686564756c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jiordiviera/laravel-smart-scheduler)[![License](https://camo.githubusercontent.com/59db5d93cd9898f8a376b25d452671cbd9bc8bf453fd3e89668d13417e81d61c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a696f72646976696572612f6c61726176656c2d736d6172742d7363686564756c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jiordiviera/laravel-smart-scheduler)

A Laravel package for intelligent scheduled task management with observability, reliability features, and automatic stuck task detection.

Features
--------

[](#features)

- **Task Execution Tracking**: Record every scheduled task execution with status, duration, and output
- **Overlap Prevention**: Automatically prevent concurrent executions of the same task
- **Stuck Task Detection**: Automatically detect and handle tasks that are stuck (server crash, process killed)
- **Failure Notifications**: Email notifications for failed and stuck tasks (extensible to other channels)
- **Task History**: Maintain execution history with server information
- **Purge Command**: Clean up old execution records

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.x or 12.x

Installation
------------

[](#installation)

Install via Composer:

```
composer require jiordiviera/laravel-smart-scheduler
```

Publish the configuration and migrations:

```
php artisan vendor:publish --tag=smart-scheduler-config
php artisan vendor:publish --tag=smart-scheduler-migrations
```

Run migrations:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

The package automatically registers a service provider. Configure settings in `config/smart-scheduler.php`:

```
return [
    // Days to retain execution records
    'purge_days' => 7,

    // Minutes before a task is considered stuck
    'stuck_timeout_minutes' => 60,

    'notifications' => [
        'email' => [
            'recipients' => ['admin@example.com'],
        ],
        'notify_on_stuck' => true,
    ],
];
```

Or use environment variables:

```
SMART_SCHEDULER_PURGE_DAYS=7
SMART_SCHEDULER_STUCK_TIMEOUT=60
SMART_SCHEDULER_EMAIL_RECIPIENTS=admin@example.com,ops@example.com
SMART_SCHEDULER_NOTIFY_STUCK=true
```

Usage
-----

[](#usage)

The package automatically tracks all scheduled tasks defined in `routes/console.php`:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('backup:run')->daily();
Schedule::command('reports:generate')->hourly();
```

### Viewing Execution History

[](#viewing-execution-history)

Query the `smart_schedule_runs` table:

```
use Jiordiviera\SmartScheduler\LaravelSmartScheduler\Models\ScheduleRun;

// Get recent executions
$runs = ScheduleRun::latest('started_at')->limit(10)->get();

// Get failed executions
$failed = ScheduleRun::where('status', ScheduleRun::STATUS_FAILED)->get();

// Get stuck executions
$stuck = ScheduleRun::where('status', ScheduleRun::STATUS_STUCK)->get();
```

### Purging Old Records

[](#purging-old-records)

Remove old successful and ignored records:

```
# Purge records older than configured days
php artisan smart-scheduler:purge

# Purge with custom retention period
php artisan smart-scheduler:purge --days=30

# Dry run to preview what would be deleted
php artisan smart-scheduler:purge --dry-run
```

### Detecting Stuck Tasks

[](#detecting-stuck-tasks)

Manually detect and mark stuck tasks:

```
# Detect stuck tasks (default: 60 minutes timeout)
php artisan smart-scheduler:detect-stuck

# Custom timeout
php artisan smart-scheduler:detect-stuck --timeout=30

# Dry run (preview only)
php artisan smart-scheduler:detect-stuck --dry-run

# Without sending notifications
php artisan smart-scheduler:detect-stuck --no-notify
```

> **Note**: Stuck tasks are also automatically detected when a new execution of the same task starts.

### Recommended Scheduler Setup

[](#recommended-scheduler-setup)

Add these commands to your `routes/console.php` for automatic maintenance:

```
use Illuminate\Support\Facades\Schedule;

// Purge old records weekly
Schedule::command('smart-scheduler:purge')->weekly();

// Detect stuck tasks every 30 minutes
Schedule::command('smart-scheduler:detect-stuck')->everyThirtyMinutes();
```

How It Works
------------

[](#how-it-works)

The package uses Laravel's event system to intercept scheduled task lifecycle:

```
┌─────────────────────────────────────────────────────────────────┐
│                    Task Execution Flow                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ScheduledTaskStarting                                          │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐     ┌──────────────┐                         │
│  │ Check stuck  │────▶│ Mark as stuck│ (if > timeout)          │
│  │ tasks        │     │ + notify     │                         │
│  └──────────────┘     └──────────────┘                         │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐     ┌──────────────┐                         │
│  │ Check overlap│────▶│ STATUS_IGNORED│ (if running)           │
│  └──────────────┘     └──────────────┘                         │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐                                              │
│  │STATUS_STARTING│                                              │
│  └──────────────┘                                              │
│         │                                                       │
│         ▼                                                       │
│  ScheduledTaskFinished                                          │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐     ┌──────────────┐                         │
│  │ Exit code = 0│────▶│STATUS_SUCCESS │                         │
│  └──────────────┘     └──────────────┘                         │
│         │                                                       │
│         ▼                                                       │
│  ┌──────────────┐     ┌──────────────┐                         │
│  │ Exit code ≠ 0│────▶│STATUS_FAILED  │ + notify               │
│  └──────────────┘     └──────────────┘                         │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

```

### Task Statuses

[](#task-statuses)

StatusDescription`starting`Task is currently running`success`Task completed successfully (exit code 0)`failed`Task failed (exit code ≠ 0)`ignored`Task skipped due to overlap`stuck`Task was running too long and marked as stuckExtending Notifications
-----------------------

[](#extending-notifications)

Implement `SmartNotifierInterface` to add custom notification channels:

```
use Jiordiviera\SmartScheduler\LaravelSmartScheduler\Contracts\SmartNotifierInterface;
use Jiordiviera\SmartScheduler\LaravelSmartScheduler\Models\ScheduleRun;

class SlackNotifier implements SmartNotifierInterface
{
    public function sendFailureNotification(ScheduleRun $run): void
    {
        // Send to Slack
    }

    public function sendStuckNotification(ScheduleRun $run): void
    {
        // Send to Slack
    }
}
```

Register in a service provider:

```
$this->app->singleton(SmartNotifierInterface::class, SlackNotifier::class);
```

Testing
-------

[](#testing)

```
composer test
```

Code Style
----------

[](#code-style)

```
# Check
composer pint

# Fix
composer pint:fix
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Credits
-------

[](#credits)

- [Jiordi Viera](https://github.com/jiordiviera)
- [All Contributors](../../contributors)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance72

Regular maintenance activity

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Total

2

Last Release

156d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/809a4ada50fc54fe02b1956bc85fbf9e403f3a8de208faf27dc5fd19b84d4035?d=identicon)[jiordiviera](/maintainers/jiordiviera)

---

Top Contributors

[![jiordiviera](https://avatars.githubusercontent.com/u/157500676?v=4)](https://github.com/jiordiviera "jiordiviera (59 commits)")

---

Tags

cronlaravelobservabilityphpschedulertask-management

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jiordiviera-laravel-smart-scheduler/health.svg)

```
[![Health](https://phpackages.com/badges/jiordiviera-laravel-smart-scheduler/health.svg)](https://phpackages.com/packages/jiordiviera-laravel-smart-scheduler)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
