Skip to content

refactor(request-loaders)!: Replace is_empty and is_finished with check_readiness - #2334

Open
Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:check-readiness
Open

Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:check-readiness

Conversation

@Mantisus

@Mantisus Mantisus commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

RequestLoader and RequestManager replace is_empty() and is_finished() with a single check_readiness(). It returns one of four statuses, exported from crawlee.request_loaders: ReadyStatus, WaitingStatus, StalledStatus or FinishedStatus. WaitingStatus.ready_at says when a source expects to have work again, and ThrottlingRequestManager sets it from its cooldowns. StalledStatus.reason says why a source can't make progress. Storage clients keep is_empty() and is_finished(). The upgrade guide covers the migration.

  • ThrottlingRequestManager.get_stall_reason() is removed. The crawler reads a stall from the status, so it now also detects a stalled domain when the ThrottlingRequestManager is wrapped in a RequestManagerTandem.
  • RequestManagerTandem moves a request from its loader only when the loader is ready, so a SitemapRequestLoader that's still loading sitemaps no longer holds up the requests already in the manager.
  • RequestLoader.fetch_next_request() no longer has to wait for a request. A None means nothing is pending right now, not that the loader is finished. SitemapRequestLoader.fetch_next_request() returns None once its sitemaps are loaded, instead of waiting until every fetched request is handled.

Issues

✍️ Drafted by Claude Code

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 15, 2026
@Mantisus Mantisus self-assigned this Oct 15, 2026
@Mantisus
Mantisus marked this pull request as ready for review October 15, 2026 21:59
Comment thread src/crawlee/crawlers/_basic/_basic_crawler.py Outdated

# Wait for the Playwright crawler to finish processing all requests
while not await playwright_rq.is_empty():
while not isinstance(await playwright_rq.check_readiness(), FinishedStatus):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, this is quite less convenient than how it worked before 😕.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok, then let's use literal comparison at least, so users aren't pushed into an extra import

Comment on lines +75 to +85
```python
from crawlee.request_loaders import FinishedStatus, ReadyStatus

# v1
has_requests = not await rq.is_empty()
done = await rq.is_finished()

# v2
has_requests = isinstance(await rq.check_readiness(), ReadyStatus)
done = isinstance(await rq.check_readiness(), FinishedStatus)
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As I mentioned above, this is much less convenient than before. You now need an additional import and an isinstance() check.

Maybe we could introduce helper methods for checking statuses, so determining whether an RQ is in a particular status would be a single method call?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok, then let's use literal comparison at least, so users aren't pushed into an extra import

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@janbuchar Have you considered keeping is_finished as a simple helper that wraps

isinstance(await rq.check_readiness(), FinishedStatus)

?

We could add similar helpers for the other statuses where they make sense.

I mean, the new API is a bit worse in terms of ergonomics (maybe with AI agents it doesn't matter that much?).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ok, then let's use literal comparison at least, so users aren't pushed into an extra import

Implemented in 883a68c

@vdusek
vdusek requested review from Pijukatel and vdusek October 19, 2026 11:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants