Well, I reached a compromise between what I wanted and what I am able to do.
Now I have moved jobs and failed_jobs in the "base" database. So my queue connection now points to "base" as well. Also the failed_jobs configuration is set on "base" connection (see below).
I created one supervisor configuration for each client. Important here is the --queue option where I set the client code, for instance:
command=php /path/to/my/app/artisan queue:work database --queue=team123 --tries=2 --sleep=3
In Console/Kernel.php I set the queue name for every job:
$schedule->job(new TestJob(), 'team123')
->dailyAt('09:00');
I then created a job middleware to dynamically initialize the right client's database connection based on the client code as above (team123).
public function handle($job, $next)
{
// get client's connection data from "base" table connections
// $job->queue contains the value from the supervisor configuration
$connection = Connection::query()
->where('code', $job->queue)
->first();
Config::set('database.connections.multi.database', $connection->dbname);
Config::set("database.connections.multi.username", $connection->username);
Config::set("database.connections.multi.password", $connection->password);
DB::purge('multi');
DB::reconnect('multi');
return $next($job);
}
Everything works!!! buuuuuut... if I have errors in a job, Laravel search for failed_jobs table in the client's database and not in the "base" database.
As said I already set the failed_jobs configuration to "base" connection in config/queue.php:
'failed' => [
'driver' => 'database',
'database' => 'base',
'table' => 'failed_jobs',
],
Any idea how to force failed_jobs to be searched on the "base" connection?
Thanks