Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/apify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"@crawlee/core": "^3.9.0",
"@crawlee/types": "^3.9.0",
"@crawlee/utils": "^3.9.0",
"apify-client": "^2.11.1",
"apify-client": "^2.12.0",
"fs-extra": "^11.2.0",
"ow": "^0.28.2",
"semver": "^7.5.4",
"tslib": "^2.6.2",
"ws": "^8.18.0"
}
}
}
5 changes: 1 addition & 4 deletions packages/apify/src/charging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export class ChargingManager {
private apifyClient: ApifyClient;

constructor(configuration: Configuration, apifyClient: ApifyClient) {
this.maxTotalChargeUsd = configuration.get('maxTotalChargeUsd') ?? Infinity;
if (typeof this.maxTotalChargeUsd === 'string') { // TODO workaround for incorrect Configuration class behavior
this.maxTotalChargeUsd = Infinity;
}
this.maxTotalChargeUsd = configuration.get('maxTotalChargeUsd') || Infinity; // convert `0` to `Infinity` in case the value is an empty string
this.isAtHome = configuration.get('isAtHome');
this.actorRunId = configuration.get('actorRunId');
this.purgeChargingLogDataset = configuration.get('purgeOnStart');
Expand Down
2 changes: 1 addition & 1 deletion packages/apify/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class Configuration extends CoreConfiguration {
ACTOR_USE_CHARGING_LOG_DATASET: 'useChargingLogDataset',
};

protected static override INTEGER_VARS = [...super.INTEGER_VARS, 'proxyPort', 'containerPort', 'metamorphAfterSleepMillis'];
protected static override INTEGER_VARS = [...super.INTEGER_VARS, 'proxyPort', 'containerPort', 'metamorphAfterSleepMillis', 'maxTotalChargeUsd'];

protected static override BOOLEAN_VARS = [...super.BOOLEAN_VARS, 'isAtHome', 'testPayPerEvent', 'useChargingLogDataset'];

Expand Down
15 changes: 15 additions & 0 deletions test/apify/actor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ describe('Actor', () => {
expect(openStorageSpy).toBeCalledWith(queueId, sdk.apifyClient);
expect(openStorageSpy).toBeCalledTimes(1);

// @ts-expect-error private prop
expect(queue.initialCount).toBe(10);
});

Expand Down Expand Up @@ -1030,4 +1031,18 @@ describe('Actor', () => {
expect(pushDataSpy).toHaveBeenCalledWith({ hello: 'apify' });
});
});

describe('Actor.config and PPE', () => {
test('should work', async () => {
await Actor.init();
process.env.ACTOR_MAX_TOTAL_CHARGE_USD = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this case: process.env.ACTOR_MAX_TOTAL_CHARGE_USD = '0';? In that case we probably don't want to coerce to Infinity...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhamas thoughts? it sounds fine to me, 0 is often considered to be infinity.

if we want to distinguish empty string and zero, we'd have to adjust the logic in the config class a bit (and that would first need to happen in crawlee, but we can hotfix it from the SDK too now so we are not blocked by the crawlee release). i guess it would be fine if we just check for the empty string and map the value to undefined.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is not a valid value for the total max. I think coercing to infinity is fine in that case.

expect(Actor.config.get('maxTotalChargeUsd')).toBe(0);
expect(Actor.getChargingManager().getMaxTotalChargeUsd()).toBe(Infinity);

// the value in charging manager is cached, so we cant test that here
process.env.ACTOR_MAX_TOTAL_CHARGE_USD = '123';
expect(Actor.config.get('maxTotalChargeUsd')).toBe(123);
await Actor.exit({ exit: false });
});
});
});
Loading