Esempio n. 1
0
    def _index_date_range(self, from_date=None, to_date=None):
        if not from_date and not to_date:
            self.stderr.write(
                '* At least a from date or a to date needs to be specified')
            return

        if from_date:
            from_date = timezone.make_aware(
                timezone.datetime.strptime(from_date, '%Y-%m-%d'))
        else:
            from_date = timezone.now()
        from_date = from_date.replace(hour=00, minute=00,
                                      second=00)  # Beginning of the given day

        if to_date:
            to_date = timezone.make_aware(
                timezone.datetime.strptime(to_date, '%Y-%m-%d'))
        else:
            to_date = timezone.now()
        to_date = to_date + timezone.timedelta(days=1)
        to_date = to_date.replace(hour=00, minute=00,
                                  second=00)  # Beginning of the next day

        if to_date < from_date:
            self.stderr.write('* To date cannot be before the from date')
            return

        signal_qs = Signal.objects.filter(
            updated_at__range=[from_date, to_date]).order_by('-updated_at')
        self.stdout.write(
            f'* Indexing Signals in range from {from_date:%Y-%m-%d %H:%M:%S} to '
            f'{to_date:%Y-%m-%d %H:%M:%S}, found {signal_qs.count()} signals')
        if not self._dry_run:
            SignalDocument.index_documents(queryset=signal_qs)
Esempio n. 2
0
def rebuild_index():
    if settings.FEATURE_FLAGS.get('SEARCH_BUILD_INDEX', False):
        log.info('rebuild_index - start')
        SignalDocument.index_documents()
        log.info('rebuild_index - done!')
    else:
        log.warning('rebuild_index - elastic indexing disabled')
Esempio n. 3
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!')
Esempio n. 4
0
 def handle(self, *args, **options):
     if settings.FEATURE_FLAGS.get('SEARCH_BUILD_INDEX', False):
         self.stdout.write('elastic indexing')
         delete = options['delete']
         if delete:
             SignalDocument.clear_index()
         SignalDocument.index_documents()
     else:
         self.stdout.write('elastic indexing disabled')
     self.stdout.write('done!')
Esempio n. 5
0
    def _index_signals(self, signal_ids):
        self.stdout.write(
            f'* Indexing Signals: #{", #".join(map(str, signal_ids))}')

        signal_qs = Signal.objects.filter(
            id__in=signal_ids).order_by('-updated_at')
        signal_qs_ids = signal_qs.values_list('id', flat=True)
        ids_diff = set(signal_ids) - set(signal_qs_ids)
        if ids_diff:
            self.stderr.write(
                f'* Signals not found #{", #".join(map(str, ids_diff))}')
        else:
            if not self._dry_run:
                SignalDocument.index_documents(queryset=signal_qs)
Esempio n. 6
0
 def _index_documents(self):
     self.stdout.write('* Index all Signals in bulk')
     if not self._dry_run:
         SignalDocument.index_documents()