2018-12-29 11:55:18 208次浏览 2条回答 0 悬赏 25 金钱
<?php
/**
 * Created by PhpStorm.
 * User: An
 * Date: 2018/12/29
 * Time: 11:50
 */
namespace console\controllers;
use shmilyzxt\queue\Worker;
use Yii;
use yii\console\Controller;

class WorkerController extends Controller
{
    public function actionListen($queueName='default',$attempt=10,$memeory=128,$sleep=3 ,$delay=0){
        Worker::listen(\Yii::$app->queue,$queueName,$attempt,$memeory,$sleep,$delay);
    }
}
补充于 2018-12-29 11:55
$ ./yii worker/listen
Exception 'Error' with message 'Class 'shmilyzxt\queue\Worker' not found'

in D:\xampp\htdocs\jiankang365\console\controllers\WorkerController.php:16

Stack trace:
#0 [internal function]: console\controllers\WorkerController->actionListen('default', 10, 128, 3, 0)
#1 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#2 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#3 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('listen', Array)
#4 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('listen', Array)
#5 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('worker/listen', Array)
#6 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('worker/listen', Array)
#7 D:\xampp\htdocs\jiankang365\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#8 D:\xampp\htdocs\jiankang365\yii(25): yii\base\Application->run()
#9 {main}

补充于 2018-12-29 11:56
'queue' => [
    'class' => 'shmilyzxt\queue\queues\DatabaseQueue', //队列使用的类
    'jobEvent' => [ //队列任务事件配置,目前任务支持2个事件
        'on beforeExecute' => ['shmilyzxt\queue\base\JobEventHandler','beforeExecute'],
        'on beforeDelete' => ['shmilyzxt\queue\base\JobEventHandler','beforeDelete'],
    ],
    'connector' => [//队列中间件链接器配置(这是因为使用数据库,所以使用yii\db\Connection作为数据库链接实例)
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=127.0.0.1;dbname=jiankang365',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ],
    'table' => 'jobs', //存储队列数据表名
    'queue' => 'default', //队列的名称
    'expire' => 60, //任务过期时间
    'maxJob' =>0, //队列允许最大任务数,0为不限制
    'failed' => [//任务失败日志记录(目前只支持记录到数据库)
        'logFail' => true, //开启任务失败处理
        'provider' => [ //任务失败处理类
            'class' => 'shmilyzxt\queue\failed\DatabaseFailedProvider',
            'db' => [ //数据库链接
                'class' => 'yii\db\Connection',
                'dsn' => 'mysql:host=127.0.0.1;dbname=jiankang365',
                'username' => 'root',
                'password' => '',
                'charset' => 'utf8',
            ],
            'table' => 'failed_jobs' //存储失败日志的表名
        ],
    ],
]
补充于 2018-12-29 11:56

TIM截图20181229115753.jpg

补充于 2018-12-29 13:35

This is Yii version 2.0.15.1.

补充于 2018-12-29 13:40

Yii 问个问题太难了

亿速云
您需要登录后才可以回答。登录 | 立即注册
沃斯尼达耶
主管

沃斯尼达耶

注册时间:2016-11-02
最后登录:1天前
在线时长:14小时53分
  • 粉丝4
  • 金钱645
  • 威望0
  • 积分785

热门问题