-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: session.markBad() on requestHandler error (#1709)
fixes #1635 Caused by [this](https://github.com/apify/crawlee/blob/5ff04faa85c3a6b6f02cd58a91b46b80610d8ae6/packages/browser-crawler/src/internals/browser-crawler.ts#L524). Oh, don't we all love random modifications to passed parameters...
- Loading branch information
Showing
7 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea | ||
.DS_Store | ||
node_modules | ||
package-lock.json | ||
apify_storage | ||
crawlee_storage | ||
storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM node:16 AS builder | ||
|
||
COPY /packages ./packages | ||
COPY /package*.json ./ | ||
RUN npm --quiet set progress=false \ | ||
&& npm install --only=prod --no-optional \ | ||
&& npm update | ||
|
||
FROM apify/actor-node-playwright-chrome:16-beta | ||
|
||
RUN rm -r node_modules | ||
COPY --from=builder /node_modules ./node_modules | ||
COPY --from=builder /packages ./packages | ||
COPY --from=builder /package*.json ./ | ||
COPY /apify.json ./ | ||
COPY /main.js ./ | ||
|
||
RUN echo "Installed NPM packages:" \ | ||
&& (npm list --only=prod --no-optional --all || true) \ | ||
&& echo "Node.js version:" \ | ||
&& node --version \ | ||
&& echo "NPM version:" \ | ||
&& npm --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "test-session-rotation", | ||
"version": "0.0", | ||
"buildTag": "latest", | ||
"env": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Actor } from 'apify'; | ||
import { PlaywrightCrawler } from '@crawlee/playwright'; | ||
import { ApifyStorageLocal } from '@apify/storage-local'; | ||
|
||
const mainOptions = { | ||
exit: Actor.isAtHome(), | ||
storage: process.env.STORAGE_IMPLEMENTATION === 'LOCAL' ? new ApifyStorageLocal() : undefined, | ||
}; | ||
|
||
await Actor.main(async () => { | ||
const crawler = new PlaywrightCrawler({ | ||
maxRequestRetries: 10, | ||
sessionPoolOptions: { | ||
sessionOptions: { | ||
maxErrorScore: 2, | ||
}, | ||
}, | ||
requestHandler: async ({ session }) => { | ||
const { id, usageCount, errorScore } = session; | ||
Actor.pushData({ id, usageCount, errorScore }); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
throw new Error('retry'); | ||
}, | ||
}); | ||
|
||
await crawler.run(['https://crawlee.dev/']); | ||
}, mainOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "test-session-rotation", | ||
"version": "0.0.1", | ||
"description": "Session Test - Rotation", | ||
"dependencies": { | ||
"apify": "next", | ||
"@apify/storage-local": "^2.1.0", | ||
"@crawlee/basic": "file:./packages/basic-crawler", | ||
"@crawlee/browser": "file:./packages/browser-crawler", | ||
"@crawlee/browser-pool": "file:./packages/browser-pool", | ||
"@crawlee/core": "file:./packages/core", | ||
"@crawlee/memory-storage": "file:./packages/memory-storage", | ||
"@crawlee/puppeteer": "file:./packages/puppeteer-crawler", | ||
"@crawlee/types": "file:./packages/types", | ||
"@crawlee/utils": "file:./packages/utils", | ||
"puppeteer": "*" | ||
}, | ||
"overrides": { | ||
"apify": { | ||
"@crawlee/core": "file:./packages/core", | ||
"@crawlee/utils": "file:./packages/utils" | ||
} | ||
}, | ||
"scripts": { | ||
"start": "node main.js" | ||
}, | ||
"type": "module", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { initialize, getActorTestDir, runActor, expect } from '../tools.mjs'; | ||
|
||
const testActorDirname = getActorTestDir(import.meta.url); | ||
await initialize(testActorDirname); | ||
|
||
const { datasetItems } = await runActor(testActorDirname, 4096); | ||
|
||
await expect(datasetItems.length === 11, 'Retried correct number of times'); | ||
await expect( | ||
datasetItems.map( | ||
(session) => datasetItems.filter((s) => s.id === session.id), | ||
).every((x) => x.length <= 2), 'No session used more than three times'); |
@barjin Missing await?