-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support batches API #1062
base: main
Are you sure you want to change the base?
Support batches API #1062
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,46 @@ def __init__(self, resp: Dict[str, Any]) -> None: | |
self.total: int = resp["total"] | ||
self.from_: int = resp["from"] | ||
self.next_: int = resp["next"] | ||
|
||
|
||
class Batch(CamelBase): | ||
uid: int | ||
details: Optional[Dict[str, Any]] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if any of this is legacy syntax, I tried to maintain the same style as Task as much as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though in the previous PR I would have just done: details: Dict[str, Any] Additionally, I'm assuming |
||
stats: Optional[Dict[str, Union[int, Dict[str, Any]]]] = None | ||
duration: Optional[str] = None | ||
started_at: Optional[datetime] = None | ||
finished_at: Optional[datetime] = None | ||
progress: Optional[Dict[str, Union[float, List[Dict[str, Any]]]]] = None | ||
|
||
if is_pydantic_2(): | ||
|
||
@pydantic.field_validator("started_at", mode="before") # type: ignore[attr-defined] | ||
@classmethod | ||
def validate_started_at(cls, v: str) -> Optional[datetime]: # pylint: disable=invalid-name | ||
return iso_to_date_time(v) | ||
|
||
@pydantic.field_validator("finished_at", mode="before") # type: ignore[attr-defined] | ||
@classmethod | ||
def validate_finished_at(cls, v: str) -> Optional[datetime]: # pylint: disable=invalid-name | ||
return iso_to_date_time(v) | ||
|
||
else: # pragma: no cover | ||
|
||
@pydantic.validator("started_at", pre=True) | ||
@classmethod | ||
def validate_started_at(cls, v: str) -> Optional[datetime]: # pylint: disable=invalid-name | ||
return iso_to_date_time(v) | ||
|
||
@pydantic.validator("finished_at", pre=True) | ||
@classmethod | ||
def validate_finished_at(cls, v: str) -> Optional[datetime]: # pylint: disable=invalid-name | ||
return iso_to_date_time(v) | ||
|
||
|
||
class BatchResults: | ||
def __init__(self, resp: Dict[str, Any]) -> None: | ||
self.results: List[Batch] = [Batch(**batch) for batch in resp["results"]] | ||
self.total: int = resp["total"] | ||
self.limit: int = resp["limit"] | ||
self.from_: int = resp["from"] | ||
self.next_: int = resp["next"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this class mostly the same as the Task model, including (some) of the validations.
I used
Optional[*]
instead of theUnion[*, None]
which was widely used in Task.