Repository navigation
fix: set the log level per run and answer callers when the run migrates #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikitachapovskii-dev
wants to merge
5
commits into
fix/bound-standby-crawlers
from
fix/log-level-and-migration-notice
+176
−24
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c997000
fix: set the log level per run and answer callers when the run migrates
nikitachapovskii-dev 366b943
fix: size the shared crawler pool from the run, not from a request
nikitachapovskii-dev 1e19af8
fix: tell the caller when the search fails, and stop writing results …
nikitachapovskii-dev f9cc5bb
fix: let in-flight requests finish before the run moves, and refuse n…
nikitachapovskii-dev 0a08078
fix: stop charging for a search whose caller is already gone
nikitachapovskii-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { ContentCrawlerStatus } from '../src/const.js'; | ||
| import { createAndStartSearchCrawler } from '../src/crawlers.js'; | ||
| import { | ||
| addEmptyResultToResponse, | ||
| addResultToResponse, | ||
| createResponsePromise, | ||
| failAllResponsesOnMigration, | ||
| } from '../src/responses.js'; | ||
|
|
||
| describe('a run that migrates to another server', () => { | ||
| it('tells a caller still waiting to retry, rather than leaving it on its own timeout', async () => { | ||
| const waiting = createResponsePromise('nothing-finished', 300); | ||
|
|
||
| failAllResponsesOnMigration(); | ||
|
|
||
| await expect(waiting).rejects.toThrow('Actor had to migrate to another server. Please, retry your request.'); | ||
| }); | ||
|
|
||
| // This is what makes it safe to answer at once instead of giving the crawl a grace period. | ||
| it('still returns the results a caller already has', async () => { | ||
| const waiting = createResponsePromise('one-page-finished', 300); | ||
| const url = 'https://example.com/finished'; | ||
| addEmptyResultToResponse('one-page-finished', { url, uniqueKey: url } as never); | ||
| addResultToResponse('one-page-finished', url, { | ||
| crawl: { requestStatus: ContentCrawlerStatus.HANDLED }, | ||
| metadata: { url }, | ||
| searchResult: { rank: 1 }, | ||
| } as never); | ||
|
|
||
| failAllResponsesOnMigration(); | ||
|
|
||
| await expect(waiting).resolves.toMatchObject([{ metadata: { url } }]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('a search that fails', () => { | ||
| it('tells the caller why, instead of leaving them to wait out their own timeout', async () => { | ||
| const waiting = createResponsePromise('search-failed', 300); | ||
| const { crawler } = await createAndStartSearchCrawler({}, false); | ||
| const { failedRequestHandler } = crawler as unknown as { | ||
| failedRequestHandler: (context: unknown, err: Error) => Promise<void>; | ||
| }; | ||
|
|
||
| await failedRequestHandler( | ||
| // The request's own key is not the response's: the response is found by `responseId`. | ||
| { request: { url: 'https://www.google.com/search?q=x', uniqueKey: 'some-other-key', userData: { responseId: 'search-failed' } } }, | ||
| new Error('Google refused the request'), | ||
| ); | ||
|
|
||
| await expect(waiting).rejects.toThrow('Google refused the request'); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is an over correction in the wrong way? We can setup a shorter timeout from the requests already in flight (a race between a timeout of say 30s and the fail all response) and just create a flag to not accept new requests (that will get the fail response right away)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
Also turns out Crawlee already stops taking new pages on migration and waits up to 20s for the ones in flight.
Let's do 25s then.