Skip to content

feat: Implement the is_finished method in the ApifyStorageClient#1008

Open
Mantisus wants to merge 2 commits into
apify:masterfrom
Mantisus:queue-is-finished
Open

feat: Implement the is_finished method in the ApifyStorageClient#1008
Mantisus wants to merge 2 commits into
apify:masterfrom
Mantisus:queue-is-finished

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

Implement the is_finished method in the ApifyStorageClient

Closes: #987
Follow-up: apify/crawlee-python#1982

@Mantisus Mantisus self-assigned this Jun 22, 2026
@Mantisus Mantisus requested a review from vdusek June 22, 2026 23:26

@vdusek vdusek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One comment

Comment thread src/apify/storage_clients/_apify/_request_queue_shared_client.py Outdated
@Mantisus Mantisus requested a review from vdusek June 23, 2026 11:25

@vdusek vdusek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three more comments

async def is_finished(self) -> bool:
"""Specific implementation of this method for the RQ shared access mode."""
async with self._fetch_lock:
return await self._is_empty() and not self._queue_has_locked_requests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This relies on await self._is_empty() is being evaluated first (it calls _list_head, which populates self._queue_has_locked_requests). A reorder would break the finished detection. Maybe we could add a comment noting the ordering dependency.

@@ -279,7 +279,11 @@ async def is_empty(self) -> bool:
"""Specific implementation of this method for the RQ single access mode."""
# Without the lock the `is_empty` is prone to falsely report True with some low probability race condition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is now outdated and misleading. Could you update it?

assert metadata.pending_request_count == 0, f'metadata.pending_request_count={metadata.pending_request_count}'


async def test_is_empty_and_is_finished(request_queue_apify: RequestQueue, rq_poll_timeout: int) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the most part, this duplicates the existing test_request_queue_is_finished test. Could we consolidate them into one? And parametrized it single+shared.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the is_finished method in the ApifyStorageClient

3 participants