Skip to content

Commit

Permalink
Try to implement frontier slot count
Browse files Browse the repository at this point in the history
  • Loading branch information
phrfpeixoto committed Feb 24, 2021
1 parent c70137a commit 210c547
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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)

0 comments on commit 210c547

Please sign in to comment.