1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-20 22:54:05 +00:00

Add comments for clarity (re-fetching and event firing)

This commit is contained in:
lukinovec 2026-06-12 11:47:39 +02:00
parent 4b989d87b0
commit 698589edbd

View file

@ -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());