Skip to content

Commit 54f7f8b

Browse files
authored
feat: Add new methods to ChargingManager (#580)
Add `get_charged_event_count` and `get_max_total_charge_usd` methods, which are already available in SDK JS, but are missing here.
1 parent fa7642e commit 54f7f8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/apify/_charging.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def get_pricing_info(self) -> ActorPricingInfo:
6464
This can be used for instance when your code needs to support multiple pricing models in transition periods.
6565
"""
6666

67+
def get_charged_event_count(self, event_name: str) -> int:
68+
"""Get the number of events with the given name that were charged so far.
69+
70+
Args:
71+
event_name: Name of the inspected event.
72+
"""
73+
74+
def get_max_total_charge_usd(self) -> Decimal:
75+
"""Get the configured maximum total charge for this Actor run."""
76+
6777

6878
@docs_group('Charging')
6979
@dataclass(frozen=True)
@@ -309,6 +319,15 @@ def get_pricing_info(self) -> ActorPricingInfo:
309319
},
310320
)
311321

322+
@ensure_context
323+
def get_charged_event_count(self, event_name: str) -> int:
324+
item = self._charging_state.get(event_name)
325+
return item.charge_count if item is not None else 0
326+
327+
@ensure_context
328+
def get_max_total_charge_usd(self) -> Decimal:
329+
return self._max_total_charge_usd
330+
312331

313332
@dataclass
314333
class ChargingStateItem:

0 commit comments

Comments
 (0)