diff --git a/scrapinghub/client/frontiers.py b/scrapinghub/client/frontiers.py index 72f4edd4..2c7d38d0 100644 --- a/scrapinghub/client/frontiers.py +++ b/scrapinghub/client/frontiers.py @@ -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 @@ -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'] diff --git a/tests/client/test_frontiers.py b/tests/client/test_frontiers.py index 1dbcb827..4f7dadc7 100644 --- a/tests/client/test_frontiers.py +++ b/tests/client/test_frontiers.py @@ -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)