1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 08:24:05 +00:00

Central queues

This commit is contained in:
Samuel Štancl 2019-10-17 18:55:39 +02:00
parent 58fbdd5281
commit 2641fae3a3
2 changed files with 25 additions and 3 deletions

View file

@ -25,8 +25,8 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
$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->app['config']["queue.connections.$connection.tenancy"] === false) {
return [];
}
$id = tenant('id');
return [

View file

@ -33,6 +33,24 @@ class QueueTest extends TestCase
return $event->job->payload()['tenant_id'] === tenant('id');
});
}
/** @test */
public function tenancy_is_not_initialized_in_non_tenant_queues()
{
$this->loadLaravelMigrations(['--database' => 'tenant']);
Event::fake();
config(['queue.connections.central' => [
'driver' => 'sync',
'tenancy' => false,
]]);
dispatch(new TestJob())->onConnection('central');
Event::assertDispatched(JobProcessing::class, function ($event) {
return ! isset($event->job->payload()['tenant_id']);
});
}
}
class TestJob implements ShouldQueue