mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
add forceRefresh option to QueueTenancyBootstrapper
This commit is contained in:
parent
27f916c323
commit
368d3cc99f
1 changed files with 19 additions and 0 deletions
|
|
@ -25,6 +25,14 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
||||||
/** @var QueueManager */
|
/** @var QueueManager */
|
||||||
protected $queue;
|
protected $queue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't persist the same tenant across multiple jobs even if they have the same tenant ID.
|
||||||
|
*
|
||||||
|
* This is useful when you're changing the tenant's state (e.g. properties in the `data` column) and want the next job to initialize tenancy again
|
||||||
|
* with the new data. Features like the Tenant Config are only executed when tenancy is initialized, so the re-initialization is needed in some cases.
|
||||||
|
*/
|
||||||
|
public static bool $forceRefresh = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The normal constructor is only executed after tenancy is bootstrapped.
|
* The normal constructor is only executed after tenancy is bootstrapped.
|
||||||
* However, we're registering a hook to initialize tenancy. Therefore,
|
* However, we're registering a hook to initialize tenancy. Therefore,
|
||||||
|
|
@ -85,6 +93,17 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (static::$forceRefresh) {
|
||||||
|
// Re-initialize tenancy between all jobs
|
||||||
|
if (tenancy()->initialized) {
|
||||||
|
tenancy()->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
tenancy()->initialize(tenancy()->find($tenantId));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (tenancy()->initialized) {
|
if (tenancy()->initialized) {
|
||||||
// Tenancy is already initialized
|
// Tenancy is already initialized
|
||||||
if (tenant()->getTenantKey() === $tenantId) {
|
if (tenant()->getTenantKey() === $tenantId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue