Pass timeout to whoosh writer, allow setting it in app.config

This commit is contained in:
Slavek Kabrda
2013-12-18 11:24:43 +01:00
parent b1b3021a48
commit 538c212a89
2 changed files with 4 additions and 1 deletions
+2
View File
@@ -41,6 +41,8 @@ from flask.ext.whooshee import Whooshee, AbstractWhoosheer
app = Flask(__name__)
app.config['WHOOSHEE_DIR'] = /tmp/whoosheers
# how long should whooshee try to acquire write lock? (defaults to 2)
app.config['WHOOSHEE_WRITER_TIMEOUT'] = 3
db = SQLAlchemy(app)
whooshee = Whooshee(app)
+2 -1
View File
@@ -93,6 +93,7 @@ class Whooshee(object):
def __init__(self, app):
self.index_path_root = app.config.get('WHOOSHEE_DIR', '') or 'whooshee'
self.search_string_min_len = app.config.get('WHOSHEE_MIN_STRING_LEN', 3)
self.writer_timeout = app.config.get('WHOOSHEE_WRITER_TIMEOUT', 2)
models_committed.connect(self.on_commit, sender=app)
if not os.path.exists(self.index_path_root):
os.makedirs(self.index_path_root)
@@ -179,7 +180,7 @@ class Whooshee(object):
def on_commit(self, app, changes):
for wh in self.__class__.whoosheers:
writer = wh.index.writer()
writer = wh.index.writer(timeout=self.writer_timeout)
for change in changes:
if change[0].__class__ in wh.models:
method_name = '{0}_{1}'.format(change[1], change[0].__class__.__name__.lower())