skip to Main Content

My Laravel Version 10, Jobs do not run asynchron. (The job gets executed but synchron)

This is my setup:

php artisan queue:table was run
php artisan queue:work runs

.env

QUEUE_CONNECTION=database

jobname.php

namespace AppJobs;

use IlluminateBusQueueable;
use AppMailPasswordResetMail;
use IlluminateSupportFacadesMail;
use IlluminateQueueSerializesModels;
use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateContractsQueueShouldBeUnique;

class SendNewPasswordResetEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $incoming;

    /**
     * Create a new job instance.
     */
    public function __construct($incoming)
    {
        $this->incoming = $incoming;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        sleep(2);
        Mail::to($this->incoming['sendTo'])->send(new PasswordResetMail(['resetLink' => $this->incoming['resetLink'], 'username' => $this->incoming['username']]));

    }
}

jobcall: (i tried these two ways of calling it. -> same result: doews’t run anynchron.)

dispatch(new SendNewPasswordResetEmail(['sendTo' => $userInputs['email'], 'resetLink' =>  $url, 'username' => $user->username]));
SendNewPasswordResetEmail::dispatch(['sendTo' => $userInputs['email'], 'resetLink' =>  $url, 'username' => $user->username])->onQueue('jobs');

phpunit.xml

<env name="QUEUE_CONNECTION" value="database"/>

config/queue.php

'default' => env('QUEUE_CONNECTION', 'database'),

migration:

public function up(): void
{
    Schema::create('jobs', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('queue')->index();
        $table->longText('payload');
        $table->unsignedTinyInteger('attempts');
        $table->unsignedInteger('reserved_at')->nullable();
        $table->unsignedInteger('available_at');
        $table->unsignedInteger('created_at');
    });
}

Also if i check the jobs tabel in the database i don’t see any jobs listed.

2

Answers


  1. Chosen as BEST ANSWER

    Running the command

    php artisan config:clear
    

    did work.

    After that I get two Jobs in the SQL jobs table as expected.


  2. Try with QUEUE_CONNECTION on redis; it will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search