RicardoAbel's avatar

Spatie multitenancy queue are not working

Im using Laravel 11 with Spatie, multi-tenancy package.

Im disapaching a job and I see the entry in jobs table, jobs are not performed. I keep an eye on the bash after runing php artisan queue:work -v but I see no jobs executed.

here is my code: (tenant has been found)

     $tenant = $this->getTenantFromLandlord("tenant1.localhost"); 

    if ($tenant) {
     // Set the tenant as the current one
     $tenant->makeCurrent(); // Set the tenant context for the job

    // Dispatch the tenant-aware job
    dispatch(new HostRegistrationEmailVerificationJob($user));

    \Log::info('Host registration email queued for ' . $user->email . ' in tenant: ' . $tenant->id);
   } else {
        throw new \Exception("Tenant could not be determined");
   }

config/multitenancy.php

    return [
        'queues_are_tenant_aware_by_default' => true, 
        'tenant_aware_jobs' => [App\Jobs\HostRegistrationEmailVerificationJob::class,
    ]];

    class HostRegistrationEmailVerificationJob implements ShouldQueue, TenantAware
    { 
    use Dispatchable, InteractsWithQueue, SerializesModels, HandlesTenantConnection;

    public $user;

     public function __construct($user)
     {
          $this->user = $user;
     }

     public function handle()
     {

       Log::info('Executing job for tenant');

     }
    }
0 likes
0 replies

Please or to participate in this conversation.