Skip to content
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

Try to implement frontier slot count #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions scrapinghub/client/frontiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ def q(self):
"""
return self.queue

def count(self):
return self.q.count()

def delete(self):
"""Delete the slot."""
origin = self._frontier._frontiers._origin
Expand Down Expand Up @@ -380,3 +383,10 @@ def delete(self, ids):
"""Delete request batches from the queue."""
origin = self._frontier._frontiers._origin
return origin.delete(self._frontier.key, self.key, ids)

def count(self):
"""Counts the request queue"""
origin = self._frontier._frontiers._origin
path = (self._frontier.key, 's', self.key, 'q', 'count')
response = next(origin.apiget(path))
return response['count']
9 changes: 9 additions & 0 deletions tests/client/test_frontiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,12 @@ def test_frontier_newcount(project, frontier):
assert first_slot.newcount == 2

frontier._frontiers.close()


def test_slot_count(project, frontier):
_clean_project_frontiers(project)
first_slot = frontier.get(TEST_FRONTIER_SLOT)

_count = first_slot.q.count()
fps = [fp for fp in first_slot.q.iter()]
assert _count == len(fps)
Loading