Yesterday I noticed this really weird Laravel queue behavior. Please help me understand what is going on.
$ laravel new test
$ cd test
$ php artisan make:job TestQueue
Paste the following into the TestQueue class. Nothing fancy, really:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class TestQueue implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
Log::info('Creating ' . $id);
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info('Running ' . $this->id);
}
}
Now, regardless of the QUEUE_CONNECTION env var (redis
, beanstalkd
, even sync
!), I get the following behavior:
Please note I have php artisan queue:work
running in a separate terminal.
$ php artisan tinker
>>> App\Jobs\TestQueue::dispatch(1)
logs:
[2018-10-30 22:38:01] local.INFO: Creating 1
>>> App\Jobs\TestQueue::dispatch(2)
logs:
[2018-10-30 22:38:04] local.INFO: Creating 2
[2018-10-30 22:38:06] local.INFO: Running 1
>>> App\Jobs\TestQueue::dispatch(3)
logs:
[2018-10-30 22:38:22] local.INFO: Creating 3
[2018-10-30 22:38:24] local.INFO: Running 2
I believe not only the queue, regardless of the driver, should pick up the first job and process it whenever queue is ready, but the sync driver should process every queued job immediately (calling its handle()
method).
I feel like someone's trying to prove me 1+1=3 and I just can't see what I'm doing wrong. I'm sure this is not a bug in the framework, because the internet would be raving about it, and it is not.
Thank you for your time.
Laravel Framework 5.7.12
Edit: local environment, config is not cached
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ACG8wg
via IFTTT
Aucun commentaire:
Enregistrer un commentaire