mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54: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 */
|
||||
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.
|
||||
* However, we're registering a hook to initialize tenancy. Therefore,
|
||||
|
|
@ -85,6 +93,17 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
return;
|
||||
}
|
||||
|
||||
if (static::$forceRefresh) {
|
||||
// Re-initialize tenancy between all jobs
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->end();
|
||||
}
|
||||
|
||||
tenancy()->initialize(tenancy()->find($tenantId));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
// Tenancy is already initialized
|
||||
if (tenant()->getTenantKey() === $tenantId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue