ivcap-lambda 0.8.6__tar.gz → 0.8.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ivcap-lambda
3
- Version: 0.8.6
3
+ Version: 0.8.7
4
4
  Summary: Helper functions for building lambda-style services on the IVCAP platform
5
5
  License-File: AUTHORS.md
6
6
  License-File: LICENSE
@@ -65,11 +65,12 @@ class ToolOptions(BaseModel):
65
65
  service_id: str | None = Field(
66
66
  None, description="overriding the default service id"
67
67
  )
68
- is_ready: Callable[[], bool | dict[str, Any]] | None = Field(
68
+ is_ready: Callable[[], bool | dict[str, Any] | BaseModel] | None = Field(
69
69
  None,
70
70
  description=(
71
- "Readiness check. Return a dict of info to report on /_healtz (or True), "
72
- "return False, or raise NotReadyYet(retry_after) while not ready"
71
+ "Readiness check. Return a dict or pydantic model of info to report on "
72
+ "/_healtz (or True), return False, or raise NotReadyYet(retry_after) "
73
+ "while not ready"
73
74
  ),
74
75
  )
75
76
 
@@ -7,13 +7,15 @@ from collections.abc import Awaitable, Callable
7
7
  from typing import Any
8
8
 
9
9
  from fastapi import FastAPI, HTTPException
10
+ from pydantic import BaseModel
10
11
 
11
12
  from .utils import find_first
12
13
 
13
- # A readiness check returns True (ready), False (legacy not-ready), or a dict of
14
- # extra info to add to the health reply (ready). Raising NotReadyYet also means
15
- # not-ready. Sync or async.
16
- ReadyFn = Callable[[], bool | dict[str, Any] | Awaitable[bool | dict[str, Any]]]
14
+ # A readiness check returns True (ready), False (legacy not-ready), a dict or a
15
+ # pydantic model of extra info to add to the health reply (ready). Raising
16
+ # NotReadyYet also means not-ready. Sync or async.
17
+ ReadyResult = bool | dict[str, Any] | BaseModel
18
+ ReadyFn = Callable[[], ReadyResult | Awaitable[ReadyResult]]
17
19
 
18
20
  # Global registry of readiness handlers
19
21
  _ready_handlers: list[ReadyFn] = []
@@ -68,6 +70,9 @@ async def healtz_handler() -> dict:
68
70
  retry_after = max(retry_after or 0.0, ex.retry_after)
69
71
  continue
70
72
 
73
+ if isinstance(result, BaseModel):
74
+ result = result.model_dump(by_alias=True)
75
+
71
76
  if isinstance(result, dict):
72
77
  info.update(result)
73
78
  elif not result:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ivcap-lambda"
3
- version = "0.8.6"
3
+ version = "0.8.7"
4
4
  description = "Helper functions for building lambda-style services on the IVCAP platform"
5
5
 
6
6
  authors = ["Max Ott <max.ott@csiro.au>"]
File without changes
File without changes
File without changes