Replies: 3 comments 6 replies
-
It would be best if you used the landlord connection as default. |
Beta Was this translation helpful? Give feedback.
-
I managed to make it work doing a bit of manual work (using landlord as default connection as you recommended): Job handle method: public function handle()
{
$id_tenant = $this->job->payload()['tenantId'];
$tenant = Tenant::find($id_tenant);
config([
'database.connections.tenant.host"'=> $tenant->host,
'database.connections.tenant.database' => trim($tenant->database),
'database.connections.tenant.port"'=> $tenant->port ?? '3050',
'database.connections.tenant.username' => $tenant->username,
'database.connections.tenant.password' => $tenant->password,
]);
config(['database.default' => 'tenant']);
DB::reconnect('tenant');
UsuarioDispositivo::find($this->id_usuario_dispositivo)->forceDelete();
DB::purge('tenant');
} I intend to move this logic to Queue::before/after so all jobs have it. That would fix my problem I think (it fixed direct in the job but that code is not final as it should apply to all jobs, that have a tenantId in the payload). But I have a problem that I cannot pass a model to a job because it somehow keeps the job running. I need help to debug where it is happening because if I pass anything like a int, string, etc instead of a model the job doesn't even fail or throw any error messages it just keeps "running" forever. This works: public function __construct(int $id_usuario_dispositivo)
{
$this->id_usuario_dispositivo = $id_usuario_dispositivo;
} this doesn't work public function __construct(UsuarioDispositivo $usuario_dispositivo)
{
// etc..
} *It works once, job runs and done right after however if I send another one to the queue it is stuck. I'm on Laravel 9, last version of the package, using Redis as queue driver. I really want to find out what's happening...it sucks to not know where to go :/ I think is when something resolves the serializaed model but I lack the knowledge to go further, please advise! |
Beta Was this translation helpful? Give feedback.
-
Dont think I can share code from work :/ Give me your best guess 🙂 |
Beta Was this translation helpful? Give feedback.
-
I have wrote this question many times but I think I can see the issue now so I will rewrite:
The default DB_CONNECTION set on .env should be the landlord or the tenant?
I have it set as the tenant and when a job starts it is using a tenant connection with empty host.
I think this may be the root cause since It may attempt to find the tenant in a "bogus" tenant connection.
Beta Was this translation helpful? Give feedback.
All reactions