예제 #1
0
파일: tasks.py 프로젝트: vanbuiten/signals
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()
예제 #2
0
파일: tasks.py 프로젝트: vanbuiten/signals
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!')
예제 #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')
예제 #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!')
예제 #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)