Skip to content

Commit

Permalink
add forceRefresh option to QueueTenancyBootstrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Feb 19, 2022
1 parent 27f916c commit 368d3cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Bootstrappers/QueueTenancyBootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,6 +93,17 @@ protected static function initializeTenancyForQueue($tenantId)
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) {
Expand Down

0 comments on commit 368d3cc

Please sign in to comment.