9
9
from pydantic import TypeAdapter
10
10
11
11
from apify ._models import ActorRun , PricingModel
12
+ from apify ._utils import docs_group
12
13
from apify .log import logger
13
14
from apify .storages import Dataset
14
15
21
22
run_validator : TypeAdapter [ActorRun | None ] = TypeAdapter (Union [ActorRun , None ])
22
23
23
24
25
+ @docs_group ('Classes' )
24
26
class ChargingManager :
25
27
LOCAL_CHARGING_LOG_DATASET_NAME = 'charging_log'
26
28
@@ -185,7 +187,7 @@ def calculate_chargeable() -> dict[str, int | None]:
185
187
)
186
188
187
189
def calculate_total_charged_amount (self ) -> Decimal :
188
- """Calculate the total amount of money charged for pay-per-event events."""
190
+ """Calculate the total amount of money charged for pay-per-event events so far ."""
189
191
if self ._charging_state is None :
190
192
raise RuntimeError ('Charging manager is not initialized' )
191
193
@@ -215,7 +217,10 @@ def calculate_max_event_charge_count_within_limit(self, event_name: str) -> int
215
217
return math .floor (result ) if result .is_finite () else None
216
218
217
219
def get_pricing_info (self ) -> ActorPricingInfo :
218
- """Retrieve detailed infor about the effective pricing of the current Actor run."""
220
+ """Retrieve detailed information about the effective pricing of the current Actor run.
221
+
222
+ This can be used for instance when your code needs to support multiple pricing models in transition periods.
223
+ """
219
224
if self ._charging_state is None :
220
225
raise RuntimeError ('Charging manager is not initialized' )
221
226
@@ -231,11 +236,17 @@ def get_pricing_info(self) -> ActorPricingInfo:
231
236
)
232
237
233
238
239
+ @docs_group ('Data structures' )
234
240
@dataclass (frozen = True )
235
241
class ChargeResult :
236
242
event_charge_limit_reached : bool
243
+ """If true, no more events of this type can be charged within the limit"""
244
+
237
245
charged_count : int
246
+ """Total amount of charged events - may be lower than the requested amount"""
247
+
238
248
chargeable_within_limit : dict [str , int | None ]
249
+ """How many events of each known type can still be charged within the limit"""
239
250
240
251
241
252
@dataclass
0 commit comments