ChargingManager
Index
Constructors
constructor
Parameters
configuration: Configuration
apifyClient: ApifyClient
Returns ChargingManager
Accessors
isInitialized
Whether ChargingManager.init has run. All charging operations (including ChargingManager.getPricingInfo) require an initialized manager.
Returns boolean
isPayPerEvent
A shortcut - true if the Actor runs with the pay-per-event pricing model.
Returns boolean
Methods
calculateChargeableWithinLimit
How many events of each known type can still be charged within the limit.
Returns Record<string, number>
calculateMaxEventChargeCountWithinLimit
How many events of a given type can still be charged for before reaching the limit; If the event is not registered, returns Infinity (free of charge)
Parameters
eventName: string
Returns number
calculatePushDataLimit
How many of
itemsCountitems may be pushed to a dataset within the remaining budget.The budget is measured against the combined per-item price of the explicit
eventNameand - on the default dataset - the synthetic DEFAULT_DATASET_ITEM_EVENT, since pushing one item charges both.When the budget cannot cover a single item, one item is still allowed through so that the resulting overcharge makes the platform terminate the run - unless the run is already strictly over budget, in which case nothing is allowed through.
Parameters
itemsCount: number
__namedParameters: { eventName?: string; isDefaultDataset?: boolean } = {}
optionaleventName: string
optionalisDefaultDataset: boolean = false
Returns number
charge
Charge for a specified number of events - sub-operations of the Actor.
This method attempts to charge for the specified number of events, but may charge fewer if doing so would exceed the total budget limit (
maxTotalChargeUsd).Important: When using the
countparameter to charge for multiple events at once, be aware that the charge may be partially fulfilled, i.e.chargedCountcan be less than the requestedcount. Always check the returnedchargedCountto know how many events were actually charged, and only perform that much work. If your work is meaningfully divisible into individual units, prefer callingcharge()once per unit rather than batching viacount— this gives finer control over budget consumption and avoids situations where more work is requested than the budget allows.Parameters
options: ChargeOptions
The name of the event to charge for and the number of events to be charged.
Returns Promise<ChargeResult>
getChargedEventCount
Get the number of events with given name that the Actor has charged for so far.
Parameters
eventName: string
Returns number
getMaxTotalChargeUsd
Get the maximum amount of money that the Actor is allowed to charge.
Returns number
getPricingInfo
Get information about the pricing for this Actor.
Returns ActorPricingInfo
init
Initialize the ChargingManager by loading pricing information and charging state via Apify API.
Returns Promise<void>
isEventChargeLimitReached
Whether the remaining budget is insufficient to charge even a single event of the given type. Always false when nothing is charged in the first place.
Parameters
eventName: string
Returns boolean
Handles pay-per-event charging.