Skip to content

Commit 81a62b7

Browse files
authored
refactor(UuidRequestIdProcessor): extract uuid setting logic to separate method (#152)
* refactor(UuidRequestIdProcessor): extract uuid setting logic to separate method Move the logic for setting the UUID into a dedicated setUuid method to improve code reusability and maintainability * fix(logger): simplify uuid request id handling and add tests Refactor the uuid request id processor to simplify the logic by checking for existing request id first. Add comprehensive tests to verify behavior in different coroutine scenarios. * feat(CrontabExecutorAspect): add timestamp to crontab execution logs Add created_at field to track when crontab executions occur
1 parent 35d01ce commit 81a62b7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Logger/UuidRequestIdProcessor.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,23 @@ public function __invoke(LogRecord $record)
3030

3131
public static function getUuid(): string
3232
{
33+
$requestId = Context::get(self::REQUEST_ID);
34+
if ($requestId) {
35+
return $requestId;
36+
}
3337
if (Coroutine::inCoroutine()) {
34-
$requestId = Context::get(self::REQUEST_ID);
35-
if ($requestId === null) {
36-
$requestId = Context::get(self::REQUEST_ID, null, Coroutine::parentId());
37-
if ($requestId !== null) {
38-
Context::set(self::REQUEST_ID, $requestId);
39-
}
40-
}
41-
if ($requestId === null) {
42-
$requestId = Uuid::uuid4()->toString();
38+
$requestId = Context::get(self::REQUEST_ID, null, Coroutine::parentId());
39+
if ($requestId !== null) {
40+
self::setUuid($requestId);
41+
return $requestId;
4342
}
44-
} else {
45-
$requestId = Context::set(self::REQUEST_ID, Uuid::uuid4()->toString());
4643
}
47-
return $requestId;
44+
45+
return self::setUuid(Uuid::uuid4()->toString());
46+
}
47+
48+
public static function setUuid(string $requestId): string
49+
{
50+
return Context::set(self::REQUEST_ID, $requestId);
4851
}
4952
}

0 commit comments

Comments
 (0)