Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/apify/_charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Loading