From a07c6a6ca2b1f7f7fc2a61d71cb0b31a665cdff7 Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Thu, 4 Sep 2025 09:30:00 +0200 Subject: [PATCH] feat: Add new methods to ChargingManager Add get_charged_event_count and get_max_total_charge_usd methods which are already available in SDK JS, but are missing here. --- src/apify/_charging.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/apify/_charging.py b/src/apify/_charging.py index 65cce951..4d95d9b5 100644 --- a/src/apify/_charging.py +++ b/src/apify/_charging.py @@ -64,6 +64,16 @@ def get_pricing_info(self) -> ActorPricingInfo: This can be used for instance when your code needs to support multiple pricing models in transition periods. """ + def get_charged_event_count(self, event_name: str) -> int: + """Get the number of events with the given name that were charged so far. + + Args: + event_name: Name of the inspected event. + """ + + def get_max_total_charge_usd(self) -> Decimal: + """Get the configured maximum total charge for this Actor run.""" + @docs_group('Charging') @dataclass(frozen=True) @@ -309,6 +319,15 @@ def get_pricing_info(self) -> ActorPricingInfo: }, ) + @ensure_context + def get_charged_event_count(self, event_name: str) -> int: + item = self._charging_state.get(event_name) + return item.charge_count if item is not None else 0 + + @ensure_context + def get_max_total_charge_usd(self) -> Decimal: + return self._max_total_charge_usd + @dataclass class ChargingStateItem: