PHPackages                             kfosoft/yii2-queue-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. [Queues &amp; Workers](/categories/queues)
4. /
5. kfosoft/yii2-queue-scheduler

ActiveYii2-extension[Queues &amp; Workers](/categories/queues)

kfosoft/yii2-queue-scheduler
============================

Extension provides functionality for make scheduled job for yii2-queue lib

20.09(5y ago)0268MITPHPPHP &gt;=7.2

Since May 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kfosoft/yii2-queue-scheduler)[ Packagist](https://packagist.org/packages/kfosoft/yii2-queue-scheduler)[ RSS](/packages/kfosoft-yii2-queue-scheduler/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (4)Used By (0)

### Yii2 Queue Scheduler

[](#yii2-queue-scheduler)

Yii2 extension for `yiisoft/yii2-queue` library

### Install

[](#install)

`composer require kfosoft/yii2-queue-scheduler`

### Configure

[](#configure)

For both(web, console) configs

```
    'components' => [
        kfosoft\queue\components\QueueScheduler::COMPONENT_NAME => [
            'class'              => kfosoft\queue\components\QueueScheduler::class,
            'modelClassName'     => 'default', // you can change model class name for don't use SchedulerQueueModel. But this class has to be implement the SchedulerQueueModelInterface
            'tableName'          => kfosoft\queue\models\SchedulerQueueModel::tableName(), // you can change name of database table without change SchedulerQueueModel
            'queueComponentName' => 'queue', // name of queue component yiisoft/yii2-queue
            'db'                 => 'db', // name of database component
            'daemonSleepTime'    => 10, // this timeout defines time between reading of SchedulerQueue database
        ],
        ...
    ],
    ...

```

For console config

```
    'bootstrap' => ['queue', kfosoft\queue\components\QueueScheduler::COMPONENT_NAME, ...],
    ...

```

And migrate the migration from repository

### To run daemon

[](#to-run-daemon)

```
bin/yii queue-scheduler

```

NOTE: To make it work properly you have to choose one of the options:

- `supervisor` look at the supervisor config in repository
- `cron` with WatcherDaemon(NOT TESTED).

```
namespace console\controllers;

use kfosoft\daemon\WatcherDaemon;

class WatcherDaemonController extends WatcherDaemon
{
    /**
     * @return array
     */
    protected function defineJobs()
    {
        sleep($this->sleep);

        //TODO: modify list, or get it from config, it does not matter
        $daemons = [
            ['className' => \kfosoft\queue\commands\SchedulerDaemonController::class, 'enabled' => true],
        ];

        return $daemons;
    }
}

```

Then add this line to crontab

```
* * * * * /path/to/yii/project/yii watcher-daemon --demonize=1

```

### Using

[](#using)

- In order to use scheduler you have to create job and implement `ScheduledJobInterface`. Also you have to implement `getJobParams` method in job class. It has to return the array fields values for creating a job. For example:

```
