Skip to content

Commit 9ffe067

Browse files
committed
Add timeout to Index.clean, current default is 60 secs.
1 parent 7487e2f commit 9ffe067

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

splunklib/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,22 @@ def attach(self, host=None, source=None, sourcetype=None):
421421
cn.write("\r\n")
422422
return cn
423423

424-
def clean(self):
424+
def clean(self, timeout=60):
425425
"""Delete the contents of the index."""
426426
saved = self.refresh()('maxTotalDataSizeMB', 'frozenTimePeriodInSecs')
427427
self.update(maxTotalDataSizeMB=1, frozenTimePeriodInSecs=1)
428428
self.roll_hot_buckets()
429-
while True: # Wait until event count goes to zero
429+
430+
# Wait until the event count goes to zero
431+
count = 0
432+
while self.content.totalEventCount != '0' and count < timeout:
430433
sleep(1)
431-
if self.refresh()['totalEventCount'] == '0': break
432-
self.update(**saved)
434+
count += 1
435+
self.refresh()
436+
437+
self.update(**saved) # Restore original values
438+
if self.content.totalEventCount != '0':
439+
raise OperationError, "Operation timed out."
433440
return self
434441

435442
def roll_hot_buckets(self):

0 commit comments

Comments
 (0)