Repository navigation
feat(crawlers)!: give each crawler after the first its own default request queue #2344
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,8 +224,9 @@ class _BasicCrawlerOptions(TypedDict): | |
| Returning `None` suppresses the status message.""" | ||
|
|
||
| id: NotRequired[str] | ||
| """A unique identifier for the crawler instance. It isolates the `use_state` state and the default statistics from | ||
| other crawlers. Without it, the ID follows the order in which crawlers are created.""" | ||
| """Identifier of the crawler. Crawlers with the same ID share the `use_state` state and the default statistics, and | ||
| every crawler but the first uses it in the alias of its default request queue. Without it, the ID follows the order | ||
| in which crawlers are created.""" | ||
|
|
||
|
|
||
| class _BasicCrawlerOptionsGeneric(TypedDict, Generic[TCrawlingContext, TStatisticsState]): | ||
|
|
@@ -371,8 +372,9 @@ def __init__( | |
| status_message_logging_interval: Interval for logging the crawler status messages. | ||
| status_message_callback: Allows overriding the default status message. The default status message is | ||
| provided in the parameters. Returning `None` suppresses the status message. | ||
| id: A unique identifier for the crawler instance. It isolates the `use_state` state and the default | ||
| statistics from other crawlers. Without it, the ID follows the order in which crawlers are created. | ||
| id: Identifier of the crawler. Crawlers with the same ID share the `use_state` state and the default | ||
| statistics, and every crawler but the first uses it in the alias of its default request queue. Without | ||
| it, the ID follows the order in which crawlers are created. | ||
| _context_pipeline: Enables extending the request lifecycle and modifying the crawling context. | ||
| Intended for use by subclasses rather than direct instantiation of `BasicCrawler`. | ||
| _additional_context_managers: Additional context managers used throughout the crawler lifecycle. | ||
|
|
@@ -381,6 +383,7 @@ def __init__( | |
| Intended for use by subclasses rather than direct instantiation of `BasicCrawler`. | ||
| """ | ||
| self._id = str(BasicCrawler.__next_id) if id is None else id | ||
| self._default_rq_alias = None if BasicCrawler.__next_id == 0 else f'__default_{self._id}__' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just double-checking since now is a good time for whatever breaking changes, are we sure that the default RQ should not have any alias?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep it. Many users run a single crawler on the default queue, and this way nothing changes for them. Also, on the Apify platform, the default queue is the run's default storage, so with an alias the first crawler's requests would go to a separate unnamed queue instead of the one the Console shows for the run. |
||
| BasicCrawler.__next_id += 1 | ||
| self._consumer = ConcurrencyConsumer(id=self._id) | ||
|
|
||
|
|
@@ -644,9 +647,10 @@ async def _get_proxy_info(self, request: Request, session: Session | None) -> Pr | |
| ) | ||
|
|
||
| async def get_request_manager(self) -> RequestManager: | ||
| """Return the configured request manager. If none is configured, open and return the default request queue.""" | ||
| """Return the configured request manager. If none is configured, open and return the crawler's own queue.""" | ||
| if not self._request_manager: | ||
| self._request_manager = await RequestQueue.open( | ||
| alias=self._default_rq_alias, | ||
| storage_client=self._service_locator.get_storage_client(), | ||
| configuration=self._service_locator.get_configuration(), | ||
| ) | ||
|
|
||
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.
Should there be some warning about multiprocessing cases breaking some assumptions and thus not behaving the same way out of the box?
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.
I don't think so. Our documentation doesn't contain any recommendations regarding multiprocessing.