Skip to main content
Version: Next

ChargingManager

Handles pay-per-event charging.

Index

Constructors

constructor

Methods

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

calculatePushDataLimits

  • calculatePushDataLimits<T>(__namedParameters): { eventsToCharge: Record<string, number>; limitedItems: T[] }
  • Helper to calculate how many items can be pushed within charging limits. Returns the limited items and count to charge.


    Parameters

    • __namedParameters: { eventName: undefined | string; isDefaultDataset: boolean; items: T | T[] }
      • eventName: undefined | string
      • isDefaultDataset: boolean
      • items: T | T[]

    Returns { eventsToCharge: Record<string, number>; limitedItems: T[] }

    • eventsToCharge: Record<string, number>
    • limitedItems: T[]

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>