Coverage for bc/kwai-bc-training/src/kwai_bc_training/trainings/training_schedule_repository.py: 100%
6 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module that defines an interface for a training schedule repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai_bc_training.trainings.training_schedule import (
7 TrainingScheduleEntity,
8 TrainingScheduleIdentifier,
9)
10from kwai_bc_training.trainings.training_schedule_query import (
11 TrainingScheduleQuery,
12)
15class TrainingScheduleNotFoundException(Exception):
16 """Raised when a training schedule can not be found."""
19class TrainingScheduleRepository(ABC):
20 """A training schedule repository."""
22 @abstractmethod
23 def create_query(self) -> TrainingScheduleQuery:
24 """Create a query for querying training schedules."""
25 raise NotImplementedError
27 @abstractmethod
28 async def get_by_id(
29 self, id_: TrainingScheduleIdentifier
30 ) -> TrainingScheduleEntity:
31 """Get the training schedule with the given id.
33 Args:
34 id_: The id of the training schedule.
36 Returns:
37 A training schedule entity.
39 Raises:
40 TrainingSchemaNotFoundException: when the training schedule cannot be found.
41 """
43 @abstractmethod
44 def get_all(
45 self,
46 query: TrainingScheduleQuery | None = None,
47 limit: int | None = None,
48 offset: int | None = None,
49 ) -> AsyncIterator[TrainingScheduleEntity]:
50 """Return all training schedules of a given query.
52 Args:
53 query: The query to use for selecting the rows.
54 limit: The maximum number of entities to return.
55 offset: Skip the offset rows before beginning to return entities.
57 Yields:
58 A list of training schedules.
59 """
60 raise NotImplementedError
62 @abstractmethod
63 async def create(
64 self, training_schedule: TrainingScheduleEntity
65 ) -> TrainingScheduleEntity:
66 """Create a new training schedule entity.
68 Args:
69 training_schedule: The training schedule to create.
70 """
71 raise NotImplementedError
73 @abstractmethod
74 async def update(self, training_schedule: TrainingScheduleEntity):
75 """Update an application entity.
77 Args:
78 training_schedule: The training schedule to update.
79 """
80 raise NotImplementedError
82 @abstractmethod
83 async def delete(self, training_schedule: TrainingScheduleEntity):
84 """Delete an application entity.
86 Args:
87 training_schedule: The training schedule to delete.
88 """
89 raise NotImplementedError