Laravel 5.4 MultiSite with site queues

My Laravel is configured with a Middleware Middleware provider that checks the subdomain of the address and based on that subdomain changes the connection on the fly to another database.

eg.

  Config::set('database.connections.mysql.host', $config['host'] );
  Config::set('database.connections.mysql.database', $config['db_name'] );
  Config::set('database.connections.mysql.username', $config['user']);
  Config::set('database.connections.mysql.password', $config['password']);
  Config::set('database.connections.mysql.prefix', $config['prefix']);
  Config::set('database.connections.mysql.theme', $config['theme']);

  // purge main to prevent issues (and potentially speed up connections??)
  DB::disconnect('main');
  DB::purge();

  DB::reconnect();
  return $next($request);

      

This all works fantastic, except that I now want to use Laravel Queues with an embedded database driver (sync works fine, but blocks user experience for long generations of reports).

Also, Artisan is not sure which database it connects to, so I assume it connects to the standard, which is a kind of supervisor database that stores all subdomains and corresponding db names, etc.

Please note, none of these databases are configured as connections in my database, they are stored in a unique management database as there are quite a few of them.

I've tried cloning the built-in queue listener and changing it to swap to a different site connection like so:

/**
 * Create a new queue listen command.
 *
 * @param  \Illuminate\Queue\Listener  $listener
 * @return void
 */
public function __construct(Listener $listener)
{
    // multisite swap
    $site = MultiSites::where('machine_name', $this->argument('site'));
    MultiSites::changeSite($site->id);

    parent::__construct();
    $this->setOutputHandler($this->listener = $listener);
}

      

But it fails with

The $ commandPath argument is missing for the Listener class.

Trying to replace the database / site like this in the fire () or handle () methods stops the $ commandPath error, however it just does nothing, ignores, and doesn't start processing any jobs from the database.

I don't understand how this would work with a multisite environment, does anyone have any ideas or am I wrong on this?

My ideal scenario would be to run a singular Queue command, have an oversight monitor that skips every database check. But I am also willing to spawn a database / site queue command if needed.

+3


source to share





All Articles