diff --git a/src/Database/Concerns/HasPending.php b/src/Database/Concerns/HasPending.php index f0d2ea0e..922c6bdf 100644 --- a/src/Database/Concerns/HasPending.php +++ b/src/Database/Concerns/HasPending.php @@ -111,6 +111,9 @@ trait HasPending return $firstOrCreate ? static::create($attributes) : null; } + // Fired before the claim, so it can fire once per attempt, including for a candidate + // that ends up being claimed by a concurrent process (in which case the loop retries). + // PendingTenantPulled (below) fires exactly once, for the pulled tenant. event(new PullingPendingTenant($pullCandidate)); $tenant = DB::transaction(function () use ($pullCandidate, $attributes): ?Tenant { @@ -122,6 +125,8 @@ trait HasPending return null; } + // The tenant's pending_since was just cleared, and e.g. a PullingPendingTenant listener + // may have made changes to the tenant, so re-fetch it to get it in the correct state. /** @var Model&Tenant $pulledTenant */ $pulledTenant = static::findOrFail($pullCandidate->getKey());