Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: Fix RQ usage in Scrapy scheduler #385

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

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ async def reboot(
The system stops the current container and starts a new one, with the same run ID and default storages.

Args:
event_listeners_timeout: How long should the Actor wait for Actor event listeners to finish before exiting
event_listeners_timeout: How long should the Actor wait for Actor event listeners to finish before exiting.
custom_after_sleep: How long to sleep for after the reboot, to wait for the container to be stopped.
"""
self._raise_if_not_initialized()
Expand Down
2 changes: 1 addition & 1 deletion 2 src/apify/scrapy/middlewares/apify_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def from_crawler(cls: type[ApifyHttpProxyMiddleware], crawler: Crawler) -> Apify
if use_apify_proxy is not True:
Actor.log.warning(
'ApifyHttpProxyMiddleware is not going to be used. Actor input field '
'"proxyConfiguration.useApifyProxy" is probably set to False.'
'"proxyConfiguration.useApifyProxy" is set to False.'
)
raise NotConfigured

Expand Down
13 changes: 11 additions & 2 deletions 13 src/apify/scrapy/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import traceback
from typing import TYPE_CHECKING

from crawlee.storage_clients import MemoryStorageClient

from apify._configuration import Configuration
from apify.apify_storage_client import ApifyStorageClient

Expand Down Expand Up @@ -52,8 +54,15 @@ def open(self, spider: Spider) -> None: # this has to be named "open"
self.spider = spider

async def open_queue() -> RequestQueue:
custom_loop_apify_client = ApifyStorageClient(configuration=Configuration.get_global_configuration())
return await RequestQueue.open(storage_client=custom_loop_apify_client)
config = Configuration.get_global_configuration()

# Use the ApifyStorageClient if the Actor is running on the Apify platform,
# otherwise use the MemoryStorageClient.
storage_client = (
ApifyStorageClient.from_config(config) if config.is_at_home else MemoryStorageClient.from_config(config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to happen in Actor.init, right? Why duplicate it here?

Copy link
Contributor Author

@vdusek vdusek Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the nested event loop, otherwise, it will result in:

RuntimeError: <asyncio.locks.Event object at 0x7c2d640c8fc0 [unset]> is bound to a different event loop

when using Apify client.

)

return await RequestQueue.open(storage_client=storage_client)

try:
self._rq = nested_event_loop.run_until_complete(open_queue())
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.