Reputation: 984
Answer: My patch to Tinker docs now made it to official Laravel documentation, see the warning frame here: https://laravel.com/docs/6.x/artisan#tinker
Yesterday I noticed this really weird Laravel queue behavior, where the queue always waits for the NEXT job to be scheduled to process the previously scheduled one. 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
Upvotes: 2
Views: 781
Reputation: 40653
As mentioned in the comment, I think this is just an artefact of using tinker instead of the web interface. I can also reproduce this with tinker but not when doing it within a web request context.
I am not sure why this happens, while tinker is very helpful for debugging purposes it might not be fully capable of handling operations like queuing.
You could file a bug with Laravel or directly at the Laravel tinker project at https://github.com/laravel/tinker
Upvotes: 1