Yii2-queue: the jobs aren't run

Neither yii queue/run nor ->run() command doesn’t work. The jobs I push are added to \web\runtime\queue. There are also \runtime\queue directory which has just an index.data file.
As far I understand queue/run supposed to run jobs from \runtime\queue while run() is meant to execute \web\runtime\queue data, so I tried to copy data from \web\runtime\queue to \runtime\queue but it still doesn’t work, the index.data is the only file being changed (if I get it right, job.data are supposed to be deleted after executing…).

Controller:

        Yii::$app->queue->push(new WriteJob([
    			'text' => 'test',
    			'file' => Yii::$app->basePath . '/web/file.txt'
    			]))/*->run()*/;

Job class:

    namespace app\models;

    use yii\base\BaseObject;

    class WriteJob extends BaseObject implements \yii\queue\JobInterface
    {
        public $text;
        public $file;

        public function execute($queue)
        {
    		file_put_contents($this->file, $this->text);
        }
    }

web.php and console.php:

 'bootstrap' => ['log', 'admin', 'queue'],
 'aliases' => [
      /*.........*/
    		'@common/mail' => 'mail',
    		'@runtime/queue' => 'runtime/queue',
        ],
    'components' => [
    /*...........*/
     'queue' => [
                'class' => \yii\queue\file\Queue::class,
                'as log' => \yii\queue\LogBehavior::class,
                'path' => '@runtime/queue',
            ],
    ]

/* specifically web.php */
'debug' => [
            'class' => \yii\debug\Module::class,
            'panels' => [
                'queue' => \yii\queue\debug\Panel::class, //doesn't work either,
            ], //not sure if it has something to do with main problem
        ],

Test file path: \web\file.txt - remains empty.
My yii2 project is on OpenServer (in Windows) if it’s somehow matter…

It looks like it’s supposed to work but it doesn’t…

What is the output of queue/run?

in console? Nothing.

Also, command yii queue/listen -v --color ends up with output like 2019-01-10 13:01:19 [pid: 6000] - Worker is started, but that’s it.

upd: I tried it with -v parameter

Can you add some output to the job execute method?

It seems execute method isn’t run…

public function execute($queue)
    {
		Yii::debug('tesssst');
                echo 'teeeest';
		file_put_contents($this->file, $this->text);
    }

I noticed that runtime\queue\index.data contains just a:0:{} while \web\runtime\index.data has the data of all jobs starting with a:2 (I wonder why not a:0…). So, I copied everything from latter index.data to the former, and all job.data as well. With having it done I got an error at least:

So, it looks like the problem is the jobs are being pushed in web but the run method looks for them in concole…

What PHP version you have?

It’s php 5.6

And I installed the extention via composer require… instead of php composer.phar… if it’s somehow matter…

Doesn’t matter if composer is used from phar or not.

It should work but based on error it looks like PHP version mismatch…

meh… php -v gives me version 5.6, same is in openserver’s php info

Try doing composer update locally instead of composer install. Looks like components installed do not match PHP version constraint.

1 Like

Yeah, it works now)
I’ve been trying “composer -upd” or something like this a few days ago but it was “there’s nothing to update” that time.
Thanks.

It’s weird, I just had the exact same issue, working on porting a legacy app to yii2 on PHP 5.6.

The problem seems to be related to yii2-queue 2.1.0 which requires “*” for symfony/process, which ends up downloading v4.x which is incompatible with PHP5.

Downgrading to last yii-queue 2.0.x seems to fix the problem.

This issue is already addressed for 2.1.1 which is not out yet: https://github.com/yiisoft/yii2-queue/issues/267

Beware, the problem may still exist but it’s working case the job is marked as reserved so symfony/process doesn’t kick in yet. Try adding a new job to the queue and run the command again.

If it still fails, set the version of yii2-queue to 2.0.2 in your composer.json & run composer update again.

1 Like

The only issue left is it works with console command but doesn’t with Yii::$app->queue->run();
So jobs.data from runtime folder are executed, that from web\runtime don’t

2019-05-08 22:04:40 [-][-][-][error][ParseError] ParseError: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE) in C:\xampp\htdocs\app\vendor\symfony\process\Process.php:140
Stack trace:
#0 C:\xampp\htdocs\yeni-portal\vendor\composer\ClassLoader.php(322): Composer\Autoload\includeFile(‘C:\xampp\htdocs…’)
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass(‘Symfony\Compone…’)
#2 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\cli\Command.php(167): spl_autoload_call(‘Symfony\Compone…’)
#3 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\cli\Command.php(106): yii\queue\cli\Command->handleMessage(‘4046’, ‘O:34:"app\modul…’, ‘300’, 1)
#4 [internal function]: yii\queue\cli\Command->yii\queue\cli{closure}(‘4046’, ‘O:34:"app\modul…’, ‘300’, 1)
#5 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\cli\Queue.php(136): call_user_func(Object(Closure), ‘4046’, ‘O:34:"app\modul…’, ‘300’, 1)
#6 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\drivers\db\Queue.php(84): yii\queue\cli\Queue->handleMessage(‘4046’, ‘O:34:"app\modul…’, ‘300’, 1)
#7 [internal function]: yii\queue\db\Queue->yii\queue\db{closure}(Object(yii\queue\cli\SignalLoop))
#8 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\cli\Queue.php(108): call_user_func(Object(Closure), Object(yii\queue\cli\SignalLoop))
#9 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\drivers\db\Queue.php(94): yii\queue\cli\Queue->runWorker(Object(Closure))
#10 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2-queue\src\drivers\db\Command.php(56): yii\queue\db\Queue->run(false)
#11 [internal function]: yii\queue\db\Command->actionRun()
#12 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#13 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#14 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction(‘run’, Array)
#15 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction(‘run’, Array)
#16 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction(‘queue/run’, Array)
#17 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction(‘queue/run’, Array)
#18 C:\xampp\htdocs\yeni-portal\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#19 C:\xampp\htdocs\yeni-portal\yii(18): yii\base\Application->run()
#20 {main}

Please open a new forum thread if you need assistance.
(and you seem to be using a library not compatible with your version of PHP)