Skip to content

Commit 210c547

Browse files
committed
Try to implement frontier slot count
1 parent c70137a commit 210c547

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

scrapinghub/client/frontiers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ def q(self):
275275
"""
276276
return self.queue
277277

278+
def count(self):
279+
return self.q.count()
280+
278281
def delete(self):
279282
"""Delete the slot."""
280283
origin = self._frontier._frontiers._origin
@@ -380,3 +383,10 @@ def delete(self, ids):
380383
"""Delete request batches from the queue."""
381384
origin = self._frontier._frontiers._origin
382385
return origin.delete(self._frontier.key, self.key, ids)
386+
387+
def count(self):
388+
"""Counts the request queue"""
389+
origin = self._frontier._frontiers._origin
390+
path = (self._frontier.key, 's', self.key, 'q', 'count')
391+
response = next(origin.apiget(path))
392+
return response['count']

tests/client/test_frontiers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,12 @@ def test_frontier_newcount(project, frontier):
138138
assert first_slot.newcount == 2
139139

140140
frontier._frontiers.close()
141+
142+
143+
def test_slot_count(project, frontier):
144+
_clean_project_frontiers(project)
145+
first_slot = frontier.get(TEST_FRONTIER_SLOT)
146+
147+
_count = first_slot.q.count()
148+
fps = [fp for fp in first_slot.q.iter()]
149+
assert _count == len(fps)

0 commit comments

Comments
 (0)