Skip to main content
Version: Next

ChargingManager

Handles pay-per-event charging.

Index

Constructors

constructor

Accessors

isInitialized

  • get isInitialized(): boolean

isPayPerEvent

  • get isPayPerEvent(): boolean
  • A shortcut - true if the Actor runs with the pay-per-event pricing model.


    Returns boolean

Methods

calculateChargeableWithinLimit

  • calculateChargeableWithinLimit(): Record<string, number>
  • How many events of each known type can still be charged within the limit.


    Returns Record<string, number>

calculateMaxEventChargeCountWithinLimit

  • calculateMaxEventChargeCountWithinLimit(eventName): number
  • 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

  • calculatePushDataLimit(itemsCount, __namedParameters): number
  • How many of itemsCount items may be pushed to a dataset within the remaining budget.

    The budget is measured against the combined per-item price of the explicit eventName and - 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 count parameter to charge for multiple events at once, be aware that the charge may be partially fulfilled, i.e. chargedCount can be less than the requested count. Always check the returned chargedCount to know how many events were actually charged, and only perform that much work. If your work is meaningfully divisible into individual units, prefer calling charge() once per unit rather than batching via count — 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

  • getChargedEventCount(eventName): number
  • Get the number of events with given name that the Actor has charged for so far.


    Parameters

    • eventName: string

    Returns number

getMaxTotalChargeUsd

  • getMaxTotalChargeUsd(): number
  • Get the maximum amount of money that the Actor is allowed to charge.


    Returns number

getPricingInfo

init

  • init(): Promise<void>
  • Initialize the ChargingManager by loading pricing information and charging state via Apify API.


    Returns Promise<void>

isEventChargeLimitReached

  • isEventChargeLimitReached(eventName): boolean
  • 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