@@ -51,15 +51,37 @@ class QuotaLimiter(ABC):
5151
5252 @abstractmethod
5353 def available_quota (self , subject_id : str ) -> int :
54- """Retrieve available quota for given user."""
54+ """Retrieve available quota for given user.
55+
56+ Get the remaining quota for the specified subject.
57+
58+ Parameters:
59+ subject_id (str): Identifier of the subject (user or service) whose quota to retrieve.
60+
61+ Returns:
62+ available_quota (int): Number of quota units currently available for the subject.
63+ """
5564
5665 @abstractmethod
5766 def revoke_quota (self ) -> None :
58- """Revoke quota for given user."""
67+ """Revoke quota for given user.
68+
69+ Revoke the quota for the limiter's target subject by setting its available quota to zero.
70+
71+ This operation removes or disables any remaining allowance so
72+ subsequent checks will report no available quota.
73+ """
5974
6075 @abstractmethod
6176 def increase_quota (self ) -> None :
62- """Increase quota for given user."""
77+ """Increase quota for given user.
78+
79+ Increase the available quota for the limiter's subject according to its
80+ configured increase policy.
81+
82+ Updates persistent storage to add the configured quota increment to the
83+ subject's stored available quota.
84+ """
6385
6486 @abstractmethod
6587 def ensure_available_quota (self , subject_id : str = "" ) -> None :
@@ -69,23 +91,59 @@ def ensure_available_quota(self, subject_id: str = "") -> None:
6991 def consume_tokens (
7092 self , input_tokens : int , output_tokens : int , subject_id : str = ""
7193 ) -> None :
72- """Consume tokens by given user."""
94+ """Consume tokens by given user.
95+
96+ Consume the specified input and output tokens from a subject's available quota.
97+
98+ Parameters:
99+ input_tokens (int): Number of input tokens to deduct from the subject's quota.
100+ output_tokens (int): Number of output tokens to deduct from the subject's quota.
101+ subject_id (str): Identifier of the subject (user or service) whose
102+ quota will be reduced. If omitted, applies to the default subject.
103+ """
73104
74105 @abstractmethod
75106 def __init__ (self ) -> None :
76- """Initialize connection configuration(s)."""
107+ """Initialize connection configuration(s).
108+
109+ Create a QuotaLimiter instance and initialize database connection configuration attributes.
110+
111+ Attributes:
112+ sqlite_connection_config (Optional[SQLiteDatabaseConfiguration]):
113+ SQLite connection configuration or `None` when not configured.
114+ postgres_connection_config
115+ (Optional[PostgreSQLDatabaseConfiguration]): PostgreSQL connection
116+ configuration or `None` when not configured.
117+ """
77118 self .sqlite_connection_config : Optional [SQLiteDatabaseConfiguration ] = None
78119 self .postgres_connection_config : Optional [PostgreSQLDatabaseConfiguration ] = (
79120 None
80121 )
81122
82123 @abstractmethod
83124 def _initialize_tables (self ) -> None :
84- """Initialize tables and indexes."""
125+ """Initialize tables and indexes.
126+
127+ Create any database tables and indexes required by the quota limiter implementation.
128+
129+ Implementations must ensure the database schema and indexes needed for
130+ storing and querying quota state exist; calling this method when the
131+ schema already exists should be safe (idempotent). Raise an exception
132+ on irrecoverable initialization failures.
133+ """
85134
86135 # pylint: disable=W0201
87136 def connect (self ) -> None :
88- """Initialize connection to database."""
137+ """Initialize connection to database.
138+
139+ Establish the configured database connection, initialize required
140+ tables, and enable autocommit.
141+
142+ If a PostgreSQL or SQLite configuration is present, a connection to
143+ that backend will be created, then _initialize_tables() will be called
144+ to prepare storage. If table initialization fails, the connection is
145+ closed and the original exception is propagated.
146+ """
89147 logger .info ("Initializing connection to quota limiter database" )
90148 if self .postgres_connection_config is not None :
91149 self .connection = connect_pg (self .postgres_connection_config )
@@ -102,7 +160,13 @@ def connect(self) -> None:
102160 self .connection .autocommit = True
103161
104162 def connected (self ) -> bool :
105- """Check if connection to quota limiter database is alive."""
163+ """Check if connection to quota limiter database is alive.
164+
165+ Determine whether the storage connection is alive.
166+
167+ Returns:
168+ `true` if the connection is alive, `false` otherwise.
169+ """
106170 if self .connection is None :
107171 logger .warning ("Not connected, need to reconnect later" )
108172 return False
0 commit comments