import sys
from xmm.util.converters import ModelNameConverter
from .base import PipelineStep
[docs]class RebuildIndexStep(PipelineStep):
"""
RebuildIndex step.
Rebuilds the Elasticsearch index for a given model.
:param str|type model: Model class name or concrete class.
:param bool raw: Use raw method to index data. Please use with caution, model links are not indexed!
"""
def __init__(self, model, raw=False):
if isinstance(model, str):
self.model = ModelNameConverter.get_model_class(model)
else:
self.model = model
self.raw = raw
def process_step(self, state, context):
return state, context
def cleanup(self, context, exception=None):
context['rebuild_index'] = self.model.rebuild_index(progress=sys.stderr.isatty(), raw=self.raw)
return context