Skip to content

Commit

Permalink
Load more charging information on platform
Browse files Browse the repository at this point in the history
  • Loading branch information
janbuchar committed Jan 9, 2025
1 parent 38ff1b6 commit 582bb0d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/apify/src/internals/charging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ export class ChargingManager {
const run = (await this.apifyClient.run(this.actorRunId!).get())!;
this.isPayPerEvent = run.pricingInfo?.pricingModel === 'PAY_PER_EVENT';

// Load per-event pricing information
if (this.isPayPerEvent) {
Object.entries(run.pricingInfo.pricingPerEvent.actorChargeEvents).forEach(([eventName, eventPricing]) => {
for (const [eventName, eventPricing] of run.pricingInfo.pricingPerEvent.actorChargeEvents) {
this.pricingInfo[eventName] = {
price: eventPricing.eventPriceUsd,
title: eventPricing.eventTitle,
};
});
}

this.maxTotalChargeUsd = run.options.maxTotalChargeUsd ?? this.maxTotalChargeUsd;
}

// TODO load charged event counts
// TODO load maxTotalChargeUsd
// Load charged event counts
for (const [eventName, chargeCount] of Object.entries(run.chargedEventCounts ?? {})) {
this.chargingState[eventName] = {
chargeCount,
totalChargedAmount: chargeCount * (this.pricingInfo[eventName]?.price ?? 0),
};
}
}

if (this.isPayPerEvent) {
Expand Down

0 comments on commit 582bb0d

Please sign in to comment.