Skip to content

Commit a26668b

Browse files
committed
Move slot deletion logic into FrontierSlot
1 parent eb53035 commit a26668b

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,13 @@ To delete a batch of requests::
471471

472472
>>> slot.delete('00013967d8af7b0001')
473473

474-
Flush data of the given frontier::
474+
To delete the whole slot from the frontier::
475475

476-
>>> frontier.flush()
476+
>>> slot.delete()
477477

478-
To delete the slot ``example.com`` from the frontier::
478+
Flush data of the given frontier::
479479

480-
>>> frontier.delete('example.com')
480+
>>> frontier.flush()
481481

482482
Flush data of all frontiers of a project::
483483

scrapinghub/client.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,7 @@ class Frontier(object):
11201120
11211121
- flush frontier data
11221122
>>> frontier.flush()
1123-
1124-
- delete slot by name
1125-
>>> frontier.delete('example.com')
11261123
"""
1127-
11281124
def __init__(self, client, frontiers, name):
11291125
self.key = name
11301126
self._client = client
@@ -1134,10 +1130,6 @@ def get(self, slot):
11341130
"""Get a slot by name."""
11351131
return FrontierSlot(self._client, self, slot)
11361132

1137-
def delete(self, slot):
1138-
"""Delete a slot by name."""
1139-
return self._frontiers._origin.delete_slot(self.key, slot)
1140-
11411133
def iter(self):
11421134
"""Iterate through slots."""
11431135
return iter(self.list())
@@ -1166,6 +1158,9 @@ class FrontierSlot(object):
11661158
>>> data = [{'fp': 'page1.html', 'p': 1, 'qdata': {'depth': 1}}]
11671159
>>> slot.add('example.com', data)
11681160
1161+
- flush data for a slot
1162+
>>> slot.flush()
1163+
11691164
- read requests from a slot
11701165
>>> slot.iter()
11711166
<generator object jldecode at 0x1049aa9e8>
@@ -1176,8 +1171,9 @@ class FrontierSlot(object):
11761171
- delete a batch with requests from a slot
11771172
>>> slot.delete('0115a8579633600006')
11781173
1179-
- flush data for a slot
1180-
>>> slot.flush()
1174+
- delete a whole slot
1175+
>>> slot.delete()
1176+
11811177
"""
11821178
def __init__(self, client, frontier, slot):
11831179
self.key = slot
@@ -1198,9 +1194,11 @@ def list(self, mincount=None):
11981194
"""List requests in slot."""
11991195
return list(self.iter(mincount=mincount))
12001196

1201-
def delete(self, ids):
1202-
"""Delete requests from slot."""
1197+
def delete(self, ids=None):
1198+
"""Delete slot or some specific requests."""
12031199
origin = self._frontier._frontiers._origin
1200+
if ids is None:
1201+
return origin.delete_slot(self._frontier.key, self.key)
12041202
return origin.delete(self._frontier.key, self.key, ids)
12051203

12061204
def flush(self):

tests/client/test_frontier.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ def test_frontier(project, frontier):
5656
assert isinstance(slot, FrontierSlot)
5757

5858
frontier.flush()
59-
frontier.delete(TEST_FRONTIER_SLOT)
60-
assert TEST_FRONTIER_SLOT not in frontier.list()
6159

6260

6361
def test_frontier_slot(project, frontier):
@@ -95,3 +93,6 @@ def test_frontier_slot(project, frontier):
9593
# drop all batches and validate that slot is empty
9694
slot.delete([batch['id'] for batch in batches])
9795
assert slot.list() == []
96+
97+
slot.delete()
98+
assert TEST_FRONTIER_SLOT not in frontier.list()

0 commit comments

Comments
 (0)