Yii2 queue doesn't work

I need to make a delayed email sending, decided to use yii2-queue component for this. But it seem not to work. I’ve been trying to just write some data in file to text it and it stays empty…

The job class:

    <?php

    namespace app\models;

    use yii\base\Object;

    class WriteJob extends Object implements \yii\queue\Job
    {
        public $text;
        public $file;

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

web.php /console.php:

    'aliases' => [
            '@bower' => '@vendor/bower-asset',
            '@npm'   => '@vendor/npm-asset',
    		'@img'   => 'web/i',
    		'@common/mail' => 'mail',
    		'@runtime/queue' => 'runtime/queue',
        ],

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

    ]

Controller:

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

The file stays empty. Some runtime data appear though

Is job executed?

It seems no…
There were some .dat files in runtime\queue folder before, but now it’s empty…

How do you run queue? cronjob or daemon process?

Just the code I wrote… I have my yii2 project just locally in OpenServer on windows, so I have no cron… I’ll have to upload it on real linux server later and it should work, I don’t have all permissions on that server…

Then it’s as it should be. Queue doesn’t execute itself. Run yii queue/run from console. It will exectute scheduled jobs once.

Aren’t yii queue/run and Yii::$app->queue ->run() the same thing? Isn’t a way to run it without console? The thing is the project is on open server now and i’ll upload it on real linux server later.

I ran yii queue/listen now, it says “worker is started” but text files remains empty when I call the controller…

There is no way to run it without console. As far as I know, open server has console as well.

Do you have job files created?

I have some .data files - index.data, job1…job14.data

@samdark @tyhja-mitaton Hello, I’ve followed this trend, and it was very helpful. I’ve a yii2 advanced setup and I’m generating the job from the backend (I’m using the file driver). I’ve found that the jobs are being created under /backend/runtime/queue but when I run php yii queue I just get the following:
Jobs

  • waiting: 0
  • delayed: 0
  • reserved: 0
  • done: 0
    As the queue/run command runs at the console and not at the backend, how can I manage to send this jobs to console runtime directory instead of backend? Any setting I’m missing out? Or should I just create a OS job to move them to the desired location?

I’d really appreciate your help on this.
Cheers!

i face the same issue, after i ran queue/run it show nothing. then what should i do ?