Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Added back support for `memory` option in `Apify.call()`

Jan Curncfaf6fa8f293
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 369c0a81a..037828557 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
-0.9.10 / 2018-11-24
+xxx
==================
+- Added back support for `memory` option in `Apify.call()`, write deprecation warning instead of silently failing
+
+0.9.10 / 2018-11-24
+===================
- Improvements in `Apify.utils.social` functions and tests
0.9.8 / 2018-11-24
@@ -43,9 +47,9 @@
- Fixed `RequestQueue.addRequest()` to gracefully handle invalid URLs
- Renamed `RequestOperationInfo` to `QueueOperationInfo`
- Added `request` field to `QueueOperationInfo`
-- **WARNING**: Parameter `timeoutSecs` of `Apify.call()` is used for actor run timeout.
+- **DEPRECATION WARNING**: Parameter `timeoutSecs` of `Apify.call()` is used for actor run timeout.
For time of waiting for run to finish use `waitSecs` parameter.
-- **WARNING**: Parameter `memory` of `Apify.call()` was renamed to `memoryMbytes`.
+- **DEPRECATION WARNING**: Parameter `memory` of `Apify.call()` was renamed to `memoryMbytes`.
- Added `Apify.callTask()` that enables to start actor task and fetch its output.
- Added option enforcing cloud storage to be used in `openKeyValueStore()`, `openDataset()` and `openRequestQueue()`
- Added `autoscaledPool.setMinConcurrency()` and `autoscaledPool.setMinConcurrency()`
diff --git a/src/actor.js b/src/actor.js
index 5dd5070c9..5c00392e1 100644
--- a/src/actor.js
+++ b/src/actor.js
@@ -240,6 +240,9 @@ export const main = (userFunc) => {
}
};
+let callMemoryWarningIssued = false;
+
+
/**
* Runs an actor on the Apify platform using the current user account (determined by the `APIFY_TOKEN` environment variable),
* waits for the actor to finish and fetches its output.
@@ -316,10 +319,22 @@ export const call = async (actId, input, options = {}) => {
checkParamOrThrow(token, 'token', 'Maybe String');
// RunAct() options.
- const { build, memoryMbytes, timeoutSecs } = optionsCopy;
+ const { build, memory, timeoutSecs } = optionsCopy;
+ let { memoryMbytes } = optionsCopy;
const runActOpts = {
actId,
};
+
+ // HOTFIX: Some old actors use "memory", so we need to keep them working for a while
+ if (memory && !memoryMbytes) {
+ memoryMbytes = memory;
+ if (!callMemoryWarningIssued) {
+ callMemoryWarningIssued = true;
+ // eslint-disable-next-line max-len
+ log.warning('The "memory" option of the Apify.call() function has been deprecated and will be removed in the future. Use "memoryMbytes" instead!');
+ }
+ }
+
checkParamOrThrow(build, 'build', 'Maybe String');
checkParamOrThrow(memoryMbytes, 'memoryMbytes', 'Maybe Number');
checkParamOrThrow(timeoutSecs, 'timeoutSecs', 'Maybe Number');
diff --git a/test/actor.js b/test/actor.js
index 555094614..6ef616e4b 100644
--- a/test/actor.js
+++ b/test/actor.js
@@ -283,6 +283,58 @@ describe('Apify.call()', () => {
});
});
+ it('supports legacy "memory" option', () => {
+ const actId = 'some-act-id';
+ const token = 'some-token';
+ const defaultKeyValueStoreId = 'some-store-id';
+ const run = { id: 'some-run-id', actId, defaultKeyValueStoreId };
+ const runningRun = Object.assign({}, run, { status: ACT_JOB_STATUSES.RUNNING });
+ const finishedRun = Object.assign({}, run, { status: ACT_JOB_STATUSES.SUCCEEDED });
+ const input = 'something';
+ const contentType = 'text/plain';
+ const output = { contentType, body: 'some-output' };
+ const expected = Object.assign({}, finishedRun, { output });
+ const build = 'xxx';
+ const memory = 8192;
+ const timeoutSecs = 60;
+
+ const actsMock = sinon.mock(Apify.client.acts);
+ actsMock.expects('runAct')
+ .withExactArgs({
+ token,
+ actId,
+ contentType: `${contentType}; charset=utf-8`,
+ body: input,
+ build,
+ memory,
+ timeout: timeoutSecs,
+ })
+ .once()
+ .returns(Promise.resolve(runningRun));
+ actsMock.expects('getRun')
+ .withExactArgs({ token, actId, runId: run.id, waitForFinish: 999999 })
+ .once()
+ .returns(Promise.resolve(runningRun));
+ actsMock.expects('getRun')
+ .withExactArgs({ token, actId, runId: run.id, waitForFinish: 999999 })
+ .once()
+ .returns(Promise.resolve(finishedRun));
+
+ const keyValueStoresMock = sinon.mock(Apify.client.keyValueStores);
+ keyValueStoresMock.expects('getRecord')
+ .withExactArgs({ storeId: run.defaultKeyValueStoreId, key: 'OUTPUT', disableBodyParser: true })
+ .once()
+ .returns(Promise.resolve(output));
+
+ return Apify
+ .call(actId, input, { contentType, token, disableBodyParser: true, build, memory, timeoutSecs })
+ .then((callOutput) => {
+ expect(callOutput).to.be.eql(expected);
+ keyValueStoresMock.restore();
+ actsMock.restore();
+ });
+ });
+
it('works without opts and input', () => {
const actId = 'some-act-id';
const token = 'token';