Coverage for src/kwai/modules/training/trainings/training_repository.py: 100%
7 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines an interface for a repository of trainings."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai.modules.training.trainings.training import TrainingEntity, TrainingIdentifier
7from kwai.modules.training.trainings.training_definition import TrainingDefinitionEntity
8from kwai.modules.training.trainings.training_query import TrainingQuery
11class TrainingNotFoundException(Exception):
12 """Raised when a training can not be found."""
15class TrainingRepository(ABC):
16 """An interface for a repository of trainings."""
18 @abstractmethod
19 def create_query(self) -> TrainingQuery:
20 """Create a query for querying trainings."""
21 raise NotImplementedError
23 @abstractmethod
24 def get_all(
25 self,
26 query: TrainingQuery | None = None,
27 limit: int | None = None,
28 offset: int | None = None,
29 ) -> AsyncIterator[TrainingEntity]:
30 """Return all trainings of a given query.
32 Args:
33 query: The query to use for selecting the rows.
34 limit: The maximum number of entities to return.
35 offset: Skip the offset rows before beginning to return entities.
37 Returns:
38 A list of trainings.
39 """
40 raise NotImplementedError
42 @abstractmethod
43 async def get_by_id(self, id: TrainingIdentifier) -> TrainingEntity:
44 """Get the training with the given id.
46 Args:
47 id: The id of the training.
49 Returns:
50 A training entity.
51 """
52 raise NotImplementedError
54 @abstractmethod
55 async def create(self, training: TrainingEntity) -> TrainingEntity:
56 """Save a training.
58 Args:
59 training: The training to save.
61 Returns:
62 A training entity with an identifier.
63 """
64 raise NotImplementedError
66 @abstractmethod
67 async def update(self, training: TrainingEntity) -> None:
68 """Update a training.
70 Args:
71 training: The training to save.
72 """
73 raise NotImplementedError
75 @abstractmethod
76 async def delete(self, training: TrainingEntity) -> None:
77 """Delete a training.
79 Args:
80 training: The training to delete.
81 """
82 raise NotImplementedError
84 @abstractmethod
85 async def reset_definition(
86 self, training_definition: TrainingDefinitionEntity, delete: bool = False
87 ) -> None:
88 """Reset all trainings of a training definition.
90 Args:
91 training_definition: The definition to use.
92 delete: Delete training or update?
94 When delete is True, trainings will be deleted. When False
95 the definition will be set to None.
96 """
97 raise NotImplementedError