mirror of
https://github.com/wassname/flask-whooshee.git
synced 2026-09-12 12:22:04 +08:00
Pass timeout to whoosh writer, allow setting it in app.config
This commit is contained in:
@@ -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
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user