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.

Fixing call() failing on run stuck in READY state

Marek Trunkatb87286dd5ac8
diff --git a/src/actor.js b/src/actor.js
index bb9ecde53..391134a6a 100644
--- a/src/actor.js
+++ b/src/actor.js
@@ -59,7 +59,8 @@ const waitForRunToFinish = async ({ actId, runId, token, waitSecs, taskId }) =>
if (!updatedRun) {
throw new ApifyCallError({ id: runId, actId }, 'Apify.call() failed, cannot fetch actor run details from the server');
}
- if (updatedRun.status !== ACT_JOB_STATUSES.SUCCEEDED && updatedRun.status !== ACT_JOB_STATUSES.RUNNING) {
+ const { status } = updatedRun;
+ if (status !== ACT_JOB_STATUSES.SUCCEEDED && (status !== ACT_JOB_STATUSES.RUNNING && status !== ACT_JOB_STATUSES.READY)) {
const message = taskId
? `The actor task ${taskId} invoked by Apify.call() did not succeed`
: `The actor ${actId} invoked by Apify.call() did not succeed`;
diff --git a/test/actor.js b/test/actor.js
index 11cc96cb6..b3e476706 100644
--- a/test/actor.js
+++ b/test/actor.js
@@ -383,6 +383,37 @@ describe('Apify.call()', () => {
});
});
+ it('should not fail when run get stuck in READY state', () => {
+ const actId = 'some-act-id';
+ const token = 'token';
+ const defaultKeyValueStoreId = 'some-store-id';
+ const run = { id: 'some-run-id', actId, defaultKeyValueStoreId };
+ const readyRun = Object.assign({}, run, { status: ACT_JOB_STATUSES.READY });
+
+ Apify.client.setOptions({ token });
+
+ const actsMock = sinon.mock(Apify.client.acts);
+ actsMock.expects('runAct')
+ .withExactArgs({ actId })
+ .once()
+ .returns(Promise.resolve(readyRun));
+ actsMock.expects('getRun')
+ .withExactArgs({ actId, runId: run.id, waitForFinish: 1 })
+ .once()
+ .returns(new Promise(resolve => setTimeout(() => resolve(readyRun), 1100)));
+
+ const keyValueStoresMock = sinon.mock(Apify.client.keyValueStores);
+ keyValueStoresMock.expects('getRecord').never();
+
+ return Apify
+ .call(actId, undefined, { waitSecs: 1 })
+ .then((callOutput) => {
+ expect(callOutput).to.be.eql(readyRun);
+ keyValueStoresMock.restore();
+ actsMock.restore();
+ });
+ });
+
it('works without opts with null input', () => {
const actId = 'some-act-id';
const token = 'token';