Skip to content

Commit

Permalink
New Config Variable: INDEXER_BEFORE_INDEX_HOOKS
Browse files Browse the repository at this point in the history
In the init_app, connects functions provided in the INDEXER_BEFORE_INDEX_HOOKS config variable to the before_record_index signal.
  • Loading branch information
zazasa committed Oct 21, 2016
1 parent b926048 commit 0e63949
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions invenio_indexer/ext.py
Expand Up @@ -26,11 +26,13 @@

from __future__ import absolute_import, print_function

import six
from flask import current_app
from werkzeug.utils import cached_property, import_string

from . import config
from .cli import run # noqa
from .signals import before_record_index


class InvenioIndexer(object):
Expand All @@ -52,6 +54,15 @@ def init_app(self, app):
self.init_config(app)
app.extensions['invenio-indexer'] = self

hooks = app.config.get('INDEXER_BEFORE_INDEX_HOOKS', [])
for hook in hooks:
if callable(hook):
before_record_index.connect_via(app)(hook)
elif isinstance(hook, six.string_types):
before_record_index.connect_via(app)(import_string(hook))
elif hook:
before_record_index.connect_via(app)(hook)

def init_config(self, app):
"""Initialize configuration.
Expand Down

0 comments on commit 0e63949

Please sign in to comment.