Skip to content

Commit

Permalink
global: add support for index templates
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Jun 14, 2024
1 parent 4a4bbcf commit 4664a57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions invenio_stats/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@
delivery_mode="transient", # in-memory queue
)
"""Default exchange used for the message queues."""

STATS_REGISTER_INDEX_TEMPLATES = False
"""Register templates as index templates.
Default behaviour will register the templates as search templates.
"""
20 changes: 18 additions & 2 deletions invenio_stats/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

"""Celery background tasks."""

from flask import current_app

from .proxies import current_stats


def register_templates():
"""Register search templates for events."""
def _collect_templates():
"""Return event and aggregation templates from config."""
event_templates = [
event["templates"] for event in current_stats.events_config.values()
]
Expand All @@ -21,3 +23,17 @@ def register_templates():
]

return event_templates + aggregation_templates


def register_templates():
"""Register search templates for events."""
if current_app.config["STATS_REGISTER_INDEX_TEMPLATES"]:
return []
return _collect_templates()


def register_index_templates():
"""Register search index templates for events."""
if not current_app.config["STATS_REGISTER_INDEX_TEMPLATES"]:
return []
return _collect_templates()
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ invenio_base.api_blueprints =
invenio_stats = invenio_stats.views:blueprint
invenio_search.templates =
invenio_stats = invenio_stats.templates:register_templates
invenio_search.index_templates =
invenio_stats = invenio_stats.templates:register_index_templates
invenio_queues.queues =
invenio_stats = invenio_stats.queues:declare_queues

Expand Down

0 comments on commit 4664a57

Please sign in to comment.