PHP code example of kfosoft / yii2-queue-scheduler

1. Go to this page and download the library: Download kfosoft/yii2-queue-scheduler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kfosoft / yii2-queue-scheduler example snippets


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;
    }
}



namespace app\jobs;

use kfosoft\queue\ScheduledJobInterface;
use Yii;
use yii\base\BaseObject;
use yii\base\InvalidConfigException;

class ImpotantJob extends BaseObject implements ScheduledJobInterface
{
    /**
     * @var int
     */
    public $param1;

    /**
     * @var string
     */
    public $param2;

    /**
     * {@inheritdoc}
     * @throws InvalidConfigException
     */
    public function execute($queue): void
    {
        // Your very important logic
    }

    /**
     * {@inheritdoc}
     */
    public function getJobParams(): array
    {
        return [
            'param1' => $this->param1,
            'param2' => $this->param2
        ];
    }
}


$job = new \app\jobs\ImpotantJob(['param1' => 1, 'param2' => 'Very important text']);
Yii::$app->get(\kfosoft\queue\components\QueueScheduler::COMPONENT_NAME)
    ->removeDelayed($job);