Skip to content

Commit 3e138c4

Browse files
yt-msMidnighter
authored andcommitted
feat: implement hydration of HTTPHealthCheck
1 parent 67e79ed commit 3e138c4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/structurizr/model/http_health_check.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
__all__ = ("HTTPHealthCheck", "HTTPHealthCheckIO")
2828

2929

30+
DEFAULT_HEALTH_CHECK_INTERVAL_IN_SECONDS = 30
31+
DEFAULT_HEALTH_CHECK_TIMEOUT_IN_MILLISECONDS = 5000
32+
33+
3034
class HTTPHealthCheckIO(BaseModel):
3135
"""
3236
Describe an HTTP-based health check.
@@ -44,8 +48,8 @@ class HTTPHealthCheckIO(BaseModel):
4448

4549
name: str = ""
4650
url: HttpUrl = ""
47-
interval: int = 30
48-
timeout: int = 5_000
51+
interval: int = DEFAULT_HEALTH_CHECK_INTERVAL_IN_SECONDS
52+
timeout: int = DEFAULT_HEALTH_CHECK_TIMEOUT_IN_MILLISECONDS
4953
headers: Dict[str, str] = Field({})
5054

5155

@@ -69,8 +73,8 @@ def __init__(
6973
*,
7074
name: str = "",
7175
url: str = "",
72-
interval: int = 30,
73-
timeout: int = 5_000,
76+
interval: int = DEFAULT_HEALTH_CHECK_INTERVAL_IN_SECONDS,
77+
timeout: int = DEFAULT_HEALTH_CHECK_TIMEOUT_IN_MILLISECONDS,
7478
headers: Iterable = (),
7579
**kwargs,
7680
):
@@ -81,3 +85,17 @@ def __init__(
8185
self.interval = interval
8286
self.timeout = timeout
8387
self.headers = dict(headers)
88+
89+
@classmethod
90+
def hydrate(
91+
cls,
92+
io: HTTPHealthCheckIO,
93+
) -> "HTTPHealthCheck":
94+
"""Hydrate a new HTTPHealthCheck instance from its IO."""
95+
return cls(
96+
name=io.name,
97+
url=io.url,
98+
interval=io.interval,
99+
timeout=io.timeout,
100+
headers=io.headers,
101+
)

0 commit comments

Comments
 (0)