Coverage for kwai/modules/training/trainings/training_definition_repository.py: 100%
6 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that defines an interface for a training definition repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai.modules.training.trainings.training_definition import (
7 TrainingDefinitionEntity,
8 TrainingDefinitionIdentifier,
9)
10from kwai.modules.training.trainings.training_definition_query import (
11 TrainingDefinitionQuery,
12)
15class TrainingDefinitionNotFoundException(Exception):
16 """Raised when a training definition can not be found."""
19class TrainingDefinitionRepository(ABC):
20 """A training definition repository."""
22 @abstractmethod
23 def create_query(self) -> TrainingDefinitionQuery:
24 """Create a query for querying training definitions."""
25 raise NotImplementedError
27 @abstractmethod
28 async def get_by_id(
29 self, id_: TrainingDefinitionIdentifier
30 ) -> TrainingDefinitionEntity:
31 """Get the training definition with the given id.
33 Args:
34 id_: The id of the training definition.
36 Returns:
37 A training definition
39 Raises:
40 TrainingDefinitionNotFoundException: when the training definition
41 cannot be found.
42 """
44 @abstractmethod
45 async def get_all(
46 self,
47 query: TrainingDefinitionQuery | None = None,
48 limit: int | None = None,
49 offset: int | None = None,
50 ) -> AsyncIterator[TrainingDefinitionEntity]:
51 """Return all training definitions of a given query.
53 Args:
54 query: The query to use for selecting the rows.
55 limit: The maximum number of entities to return.
56 offset: Skip the offset rows before beginning to return entities.
58 Yields:
59 A list of applications.
60 """
61 raise NotImplementedError
63 @abstractmethod
64 async def create(
65 self, training_definition: TrainingDefinitionEntity
66 ) -> TrainingDefinitionEntity:
67 """Create a new training definition entity.
69 Args:
70 training_definition: The training definition to create.
71 """
72 raise NotImplementedError
74 @abstractmethod
75 async def update(self, training_definition: TrainingDefinitionEntity):
76 """Update an application entity.
78 Args:
79 training_definition: The training definition to update.
80 """
81 raise NotImplementedError
83 @abstractmethod
84 async def delete(self, training_definition: TrainingDefinitionEntity):
85 """Delete an application entity.
87 Args:
88 training_definition: The training definition to delete.
89 """
90 raise NotImplementedError