Yii Framework Forum

Yii2-queue: the jobs aren't run


(tyhja-mitaton) #1

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…


(Alexander Makarov) #2

What is the output of queue/run?


(tyhja-mitaton) #3

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.


(tyhja-mitaton) #4

upd: I tried it with -v parameter


(Alexander Makarov) #5

Can you add some output to the job execute method?


(tyhja-mitaton) #6

It seems execute method isn’t run…

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

(tyhja-mitaton) #7

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…


(Alexander Makarov) #8

What PHP version you have?


(tyhja-mitaton) #9

It’s php 5.6


(tyhja-mitaton) #10

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


(Alexander Makarov) #11

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


(Alexander Makarov) #12

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


(tyhja-mitaton) #13

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


(Alexander Makarov) #14

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


(tyhja-mitaton) #15

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.


(Mehdi Achour) #16

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


(Mehdi Achour) #17

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.


(tyhja-mitaton) #18

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