Skip to content

Commit 8582980

Browse files
committed
refactor(Request): Just use microtime for start id
1 parent 70dd264 commit 8582980

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/Worker/Transport/Command/Client/Request.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Temporal\Worker\Transport\Command\Common\RequestTrait;
1919
use Temporal\Worker\Transport\Command\RequestInterface;
2020

21+
\define(['REQUEST_START_ID'][0], (int) (\microtime(true) * 1_000_000.0));
22+
2123
/**
2224
* Carries request to perform host action with payloads and failure as context. Can be cancelled if allows
2325
*
@@ -27,7 +29,7 @@ class Request implements RequestInterface
2729
{
2830
use RequestTrait;
2931

30-
protected static int $lastID = 9000;
32+
protected static int $lastID = REQUEST_START_ID;
3133
protected int $id;
3234
protected ValuesInterface $payloads;
3335
protected HeaderInterface $header;
@@ -63,9 +65,14 @@ public function getFailure(): ?\Throwable
6365
return $this->failure;
6466
}
6567

66-
protected function getNextID(): int
68+
private function getNextID(): int
6769
{
68-
static::$lastID = (static::$lastID + 1) % 1_000_000;
69-
return \time() * 1_000_000 + static::$lastID;
70+
++static::$lastID;
71+
72+
if (static::$lastID === \PHP_INT_MAX) {
73+
static::$lastID = 1;
74+
}
75+
76+
return static::$lastID;
7077
}
7178
}

tests/Fixtures/CommandResetter.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,4 @@ public static function reset(): void
1919
{
2020
self::$lastID = 9000;
2121
}
22-
23-
protected function getNextID(): int
24-
{
25-
$next = ++static::$lastID;
26-
27-
if ($next >= \PHP_INT_MAX) {
28-
$next = static::$lastID = 1;
29-
}
30-
31-
return $next;
32-
}
3322
}

0 commit comments

Comments
 (0)