diff --git a/src/Bootstrappers/QueueTenancyBootstrapper.php b/src/Bootstrappers/QueueTenancyBootstrapper.php index 2e9aa051..6a88f701 100644 --- a/src/Bootstrappers/QueueTenancyBootstrapper.php +++ b/src/Bootstrappers/QueueTenancyBootstrapper.php @@ -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) {