Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed to exit AsyncSolrIndexer thread when ticket is updated by trac-…
…admin command
  • Loading branch information
t2y committed Feb 26, 2014
1 parent 9f8fcc8 commit c8d6a03
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tracadvsearch/backend.py
Expand Up @@ -2,6 +2,7 @@
Backends for TracAdvancedSearchPlugin which implement IAdvSearchBackend.
"""
import datetime
import inspect
import itertools
import locale
import pysolr
Expand Down Expand Up @@ -115,8 +116,25 @@ def __init__(self, backend, maxsize):
self.recovery_queue = SimpleLifoQueue(maxsize)
threading.Thread.__init__(self)
self._name = self.__class__.__name__
self._is_executed_by_command = self.is_executed_by_command()

def is_executed_by_command(self):
""" HACK: check whether indexing has invoked by trac-admin command
AdminCommandManager calls execute_command function to run command.
This is quick fix, so it should be replaced with more appropriate way.
"""
# frame tuple is:
# (frame object, filename, lineno, function, code_context, index)
frames = inspect.getouterframes(inspect.currentframe(), 0)
return any(frame[3] == 'execute_command' for frame in frames)

def run(self):
if self._is_executed_by_command:
while self.indexing() and not self.queue.empty():
pass
return

prev_available = False
interval = self.interval_generator
while True:
Expand Down

0 comments on commit c8d6a03

Please sign in to comment.