Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Aug 21, 2024
1 parent b8718f8 commit 312903f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions config/bits.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
| AWS Lambda (and Laravel Vapor)
|--------------------------------------------------------------------------
|
| Snowflakes/etc rely on unique datacenter and worker IDs to operate.
| Because AWS lambdas are different machines each time, it's impossible
| Snowflakes/etc rely on unique datacenter and worker IDs to operate.
| Because AWS lambdas are different machines each time, it's impossible
| to assign each a unique worker/device ID.
|
| Bits addresses this with a special lambda ID resolver, which assigns
| and locks IDs via your cache.
|
|
| Options: true, false, or "autodetect"
*/

Expand Down
18 changes: 9 additions & 9 deletions src/IdResolvers/CacheResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ protected function acquire(): int
// reserved, or one where the reservation is expired.

return $this->lock(function() {
$reserved = $this->cache->get('glhd-bits-ids:reserved') ?? [];
$id = $this->firstAvailable($reserved) ?? $this->findExpired($reserved);
$reserved = $this->cache->get('glhd-bits-ids:reserved') ?? [];
$id = $this->firstAvailable($reserved) ?? $this->findExpired($reserved);

if (null !== $id) {
$reserved[$id] = $this->dates->now()->addHour()->unix();
$this->cache->forever('glhd-bits-ids:reserved', $reserved);
return $id;
}
if (null !== $id) {
$reserved[$id] = $this->dates->now()->addHour()->unix();
$this->cache->forever('glhd-bits-ids:reserved', $reserved);
return $id;
}

throw new RuntimeException('Unable to acquire a unique worker ID.');
});
throw new RuntimeException('Unable to acquire a unique worker ID.');
});
}

protected function release(): void
Expand Down

0 comments on commit 312903f

Please sign in to comment.