Beispiel #1
0
def save_to_elastic(signal_id):
    if not SignalDocument.ping():
        raise Exception('Elastic cluster is unreachable')

    signal = Signal.objects.get(id=signal_id)
    signal_document = SignalDocument.create_document(signal)
    signal_document.save()
Beispiel #2
0
def rebuild_index():
    log.info('rebuild_index - start')

    if not SignalDocument.ping():
        raise Exception('Elastic cluster is unreachable')

    SignalDocument.index_documents()
    log.info('rebuild_index - done!')
Beispiel #3
0
def delete_from_elastic(signal):
    if not SignalDocument.ping():
        raise Exception('Elastic cluster is unreachable')

    if isinstance(signal, int):
        signal = Signal.objects.get(id=signal)

    signal_document = SignalDocument.create_document(signal)

    try:
        signal_document.delete()
    except NotFoundError:
        log.warning(f'Signal {signal.id} not found in Elasticsearch')
Beispiel #4
0
    def handle(self, *args, **options):
        start = timer()
        self.stdout.write('Elastic management command')

        ping = True if self._dry_run else SignalDocument.ping()
        if not ping:
            self.stderr.write('* Elastic cluster is unreachable!')
        else:
            self._apply_options(**options)

        stop = timer()
        self.stdout.write(f'Time: {stop - start:.2f} second(s)')
        self.stdout.write('Done!')
Beispiel #5
0
 def list(self, request, *args, **kwargs):
     if not SignalDocument.ping():
         raise GatewayTimeoutException(
             detail='The elastic cluster is unreachable')
     return super().list(request=request, *args, **kwargs)