PHPackages                             hbalkhi/yii2-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. hbalkhi/yii2-scheduler

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

hbalkhi/yii2-scheduler
======================

A scheduled task runner for Yii2 applications

v1.0.0(2w ago)01↓100%MITPHPPHP &gt;=8.1

Since May 24Pushed 2w agoCompare

[ Source](https://github.com/hbalkhi/yii2-scheduler)[ Packagist](https://packagist.org/packages/hbalkhi/yii2-scheduler)[ Docs](https://github.com/hbalkhi/yii2-scheduler)[ RSS](/packages/hbalkhi-yii2-scheduler/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

yii2-scheduler
==============

[](#yii2-scheduler)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A scheduled task manager for Yii2 applications. Easily schedule and manage recurring tasks with a user-friendly interface and CLI commands.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Install using the following command:

```
composer require hbalkhi/yii2-scheduler
```

After installing the package, you need to configure the module in your application.

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

[](#configuration)

Update your `config/console.php` file:

```
'bootstrap' => ['log', 'scheduler'],
'modules' => [
    'scheduler' => ['class' => 'hbalkhi\scheduler\Module'],
],
'components' => [
    'errorHandler' => [
        'class' => 'hbalkhi\scheduler\ErrorHandler'
    ],
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\EmailTarget',
                'mailer' =>'mailer',
                'levels' => ['error', 'warning'],
                'message' => [
                    'to' => ['admin@example.com'],
                    'from' => [$params['adminEmail']],
                    'subject' => 'Scheduler Error - ####SERVERNAME####'
                ],
                'except' => [
                ],
            ],
        ],
    ],
]
```

Also add this to the top of your `config/console.php` file to handle scheduler events:

```
\yii\base\Event::on(
    \hbalkhi\scheduler\console\SchedulerController::className(),
    \hbalkhi\scheduler\events\SchedulerEvent::EVENT_AFTER_RUN,
    function ($event) {
        if (!$event->success) {
            foreach($event->exceptions as $exception) {
                throw $exception;
            }
        }
    }
);
```

To use the scheduler GUI in your web application, add this to your `config/web.php`:

```
'bootstrap' => ['log', 'scheduler'],
'modules' => [
    'scheduler' => ['class' => 'hbalkhi\scheduler\Module'],
],
```

After configuration, create a `tasks` directory in your project root and run the migrations to set up the database tables:

```
php yii migrate up --migrationPath=vendor/hbalkhi/yii2-scheduler/src/migrations
```

GUI Controller
--------------

[](#gui-controller)

To enable the scheduler GUI in your admin panel, create a controller like this:

```
