mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
[2.1.0] Central queue connections (#181)
* Central queues * Better dependency injection * tenancy=false => central=true; move config to env setup * Apply fixes from StyleCI
This commit is contained in:
parent
d5b01219fd
commit
cfcb2574c2
4 changed files with 34 additions and 13 deletions
|
|
@ -4,7 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\TenancyBootstrappers;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Support\Testing\Fakes\QueueFake;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
|
@ -14,19 +15,18 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
/** @var bool Has tenancy been started. */
|
||||
public $started = false;
|
||||
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
/** @var Repository */
|
||||
protected $config;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct(Repository $config, QueueManager $queue)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = $config;
|
||||
|
||||
$bootstrapper = &$this;
|
||||
|
||||
$queue = $this->app['queue'];
|
||||
if (! $queue instanceof QueueFake) {
|
||||
$queue->createPayloadUsing(function () use (&$bootstrapper) {
|
||||
return $bootstrapper->getPayload();
|
||||
$queue->createPayloadUsing(function ($connection) use (&$bootstrapper) {
|
||||
return $bootstrapper->getPayload($connection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -41,12 +41,16 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
$this->started = false;
|
||||
}
|
||||
|
||||
public function getPayload()
|
||||
public function getPayload(string $connection)
|
||||
{
|
||||
if (! $this->started) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->config["queue.connections.$connection.central"]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$id = tenant('id');
|
||||
|
||||
return [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue