Skip to content

Commit bb65f70

Browse files
authored
fix: ensure maxTotalChargeUsd is correctly mapped to number, consider empty string as infinity (#361)
1 parent 77c9bd6 commit bb65f70

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/apify/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
"@crawlee/core": "^3.9.0",
6363
"@crawlee/types": "^3.9.0",
6464
"@crawlee/utils": "^3.9.0",
65-
"apify-client": "^2.11.1",
65+
"apify-client": "^2.12.0",
6666
"fs-extra": "^11.2.0",
6767
"ow": "^0.28.2",
6868
"semver": "^7.5.4",
6969
"tslib": "^2.6.2",
7070
"ws": "^8.18.0"
7171
}
72-
}
72+
}

packages/apify/src/charging.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ export class ChargingManager {
2626
private apifyClient: ApifyClient;
2727

2828
constructor(configuration: Configuration, apifyClient: ApifyClient) {
29-
this.maxTotalChargeUsd = configuration.get('maxTotalChargeUsd') ?? Infinity;
30-
if (typeof this.maxTotalChargeUsd === 'string') { // TODO workaround for incorrect Configuration class behavior
31-
this.maxTotalChargeUsd = Infinity;
32-
}
29+
this.maxTotalChargeUsd = configuration.get('maxTotalChargeUsd') || Infinity; // convert `0` to `Infinity` in case the value is an empty string
3330
this.isAtHome = configuration.get('isAtHome');
3431
this.actorRunId = configuration.get('actorRunId');
3532
this.purgeChargingLogDataset = configuration.get('purgeOnStart');

packages/apify/src/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class Configuration extends CoreConfiguration {
172172
ACTOR_USE_CHARGING_LOG_DATASET: 'useChargingLogDataset',
173173
};
174174

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

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

test/apify/actor.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ describe('Actor', () => {
612612
expect(openStorageSpy).toBeCalledWith(queueId, sdk.apifyClient);
613613
expect(openStorageSpy).toBeCalledTimes(1);
614614

615+
// @ts-expect-error private prop
615616
expect(queue.initialCount).toBe(10);
616617
});
617618

@@ -1030,4 +1031,18 @@ describe('Actor', () => {
10301031
expect(pushDataSpy).toHaveBeenCalledWith({ hello: 'apify' });
10311032
});
10321033
});
1034+
1035+
describe('Actor.config and PPE', () => {
1036+
test('should work', async () => {
1037+
await Actor.init();
1038+
process.env.ACTOR_MAX_TOTAL_CHARGE_USD = '';
1039+
expect(Actor.config.get('maxTotalChargeUsd')).toBe(0);
1040+
expect(Actor.getChargingManager().getMaxTotalChargeUsd()).toBe(Infinity);
1041+
1042+
// the value in charging manager is cached, so we cant test that here
1043+
process.env.ACTOR_MAX_TOTAL_CHARGE_USD = '123';
1044+
expect(Actor.config.get('maxTotalChargeUsd')).toBe(123);
1045+
await Actor.exit({ exit: false });
1046+
});
1047+
});
10331048
});

0 commit comments

Comments
 (0)