mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:24:04 +00:00
end tenancy in queue if the next job is not tenant aware
This commit is contained in:
parent
9c79267e24
commit
27f916c323
3 changed files with 13 additions and 3 deletions
|
|
@ -75,14 +75,20 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected static function initializeTenancyForQueue($tenantId)
|
protected static function initializeTenancyForQueue($tenantId)
|
||||||
{
|
{
|
||||||
// The job is not tenant-aware
|
|
||||||
if (! $tenantId) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tenancy()->initialized) {
|
if (tenancy()->initialized) {
|
||||||
|
// Tenancy is already initialized
|
||||||
if (tenant()->getTenantKey() === $tenantId) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
{"userName":"Bar","shouldFail":false,"tenant_id":"The current tenant id is: a7f73c10-9879-40ae-b7b0-1ded7c1f7b1b"}
|
|
||||||
|
|
@ -55,6 +55,11 @@ class QueueTest extends TestCase
|
||||||
$this->valuestore = Valuestore::make(__DIR__ . '/Etc/tmp/queuetest.json')->flush();
|
$this->valuestore = Valuestore::make(__DIR__ . '/Etc/tmp/queuetest.json')->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->valuestore->flush();
|
||||||
|
}
|
||||||
|
|
||||||
protected function withFailedJobs()
|
protected function withFailedJobs()
|
||||||
{
|
{
|
||||||
Schema::connection('central')->create('failed_jobs', function (Blueprint $table) {
|
Schema::connection('central')->create('failed_jobs', function (Blueprint $table) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue