Skip to content

Commit b601d2b

Browse files
committed
minor
1 parent e0f45da commit b601d2b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/service-library/src/servicelib/redis/_semaphore.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from types import TracebackType
55
from typing import Annotated
66

7+
from common_library.basic_types import DEFAULT_FACTORY
78
from pydantic import (
89
BaseModel,
910
Field,
@@ -89,6 +90,13 @@ class DistributedSemaphore(BaseModel):
8990
datetime.timedelta | None,
9091
Field(description="Maximum time to wait when blocking"),
9192
] = DEFAULT_SOCKET_TIMEOUT
93+
instance_id: Annotated[
94+
str,
95+
Field(
96+
description="Unique instance identifier",
97+
default_factory=lambda: f"{uuid.uuid4()}",
98+
),
99+
] = DEFAULT_FACTORY
92100

93101
_acquire_script: AsyncScript
94102
_count_script: AsyncScript
@@ -110,15 +118,6 @@ def __init__(self, **data) -> None:
110118
RENEW_SEMAPHORE_SCRIPT
111119
)
112120

113-
# Computed fields (read-only, automatically calculated)
114-
@computed_field # type: ignore[prop-decorator]
115-
@property
116-
def instance_id(self) -> str:
117-
"""Unique identifier for this semaphore instance."""
118-
if not hasattr(self, "_instance_id"):
119-
self._instance_id = str(uuid.uuid4())
120-
return self._instance_id
121-
122121
@computed_field # type: ignore[prop-decorator]
123122
@property
124123
def semaphore_key(self) -> str:

0 commit comments

Comments
 (0)