1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 13:54:03 +00:00

end tenancy in queue if the next job is not tenant aware

This commit is contained in:
Samuel Štancl 2022-02-19 16:12:38 +01:00
parent 9c79267e24
commit 27f916c323
3 changed files with 13 additions and 3 deletions

View file

@ -75,14 +75,20 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
protected static function initializeTenancyForQueue($tenantId)
{
// The job is not tenant-aware
if (! $tenantId) {
// The job is not tenant-aware
if (tenancy()->initialized) {
// Tenancy was initialized, so we revert back to the central context
tenancy()->end();
}
return;
}
if (tenancy()->initialized) {
// Tenancy is already initialized
if (tenant()->getTenantKey() === $tenantId) {
// Tenancy is already initialized for the tenant (e.g. dispatchNow was used)
// It's initialized for the same tenant (e.g. dispatchNow was used, or the previous job also ran for this tenant)
return;
}
}

View file

@ -1 +0,0 @@
{"userName":"Bar","shouldFail":false,"tenant_id":"The current tenant id is: a7f73c10-9879-40ae-b7b0-1ded7c1f7b1b"}

View file

@ -55,6 +55,11 @@ class QueueTest extends TestCase
$this->valuestore = Valuestore::make(__DIR__ . '/Etc/tmp/queuetest.json')->flush();
}
public function tearDown(): void
{
$this->valuestore->flush();
}
protected function withFailedJobs()
{
Schema::connection('central')->create('failed_jobs', function (Blueprint $table) {