Esempio n. 1
0
    def test_date_created(self, elastic, no_celery):
        fake, real = [], []

        for i in range(1, 6):
            fake.append(
                IndexableWorkTestHelper(elastic,
                                        index=False,
                                        date=pendulum.now()))
            real.append(
                IndexableWorkTestHelper(elastic,
                                        index=False,
                                        date=pendulum.now().add(days=-i)))
        real.append(
            IndexableWorkTestHelper(elastic,
                                    index=False,
                                    date=pendulum.now().add(days=-i)))

        index_helpers(*fake)

        for helper in fake:
            helper.assert_indexed()
            helper.work.administrative_change(is_deleted=True)

        for helper in real:
            helper.assert_not_indexed()

        tasks.elasticsearch_janitor(to_daemon=False)

        for helper in real:
            helper.assert_indexed()
Esempio n. 2
0
    def test_missing_records_get_indexed(self, elastic, monkeypatch, no_celery):
        helper1 = IndexableWorkTestHelper(elastic, index=False)
        helper2 = IndexableWorkTestHelper(elastic, index=False)

        helper1.assert_not_indexed()
        helper2.assert_not_indexed()

        tasks.elasticsearch_janitor(to_daemon=False)

        helper1.assert_indexed()
        helper2.assert_indexed()
Esempio n. 3
0
    def test_missing_records_get_indexed(self, elastic, monkeypatch,
                                         no_celery):
        helper1 = IndexableWorkTestHelper(elastic, index=False)
        helper2 = IndexableWorkTestHelper(elastic, index=False)

        helper1.assert_not_indexed()
        helper2.assert_not_indexed()

        tasks.elasticsearch_janitor(to_daemon=False)

        helper1.assert_indexed()
        helper2.assert_indexed()
Esempio n. 4
0
def janitor(args, argv):
    """
    Usage: {0} search janitor [--dry | --async] [options]

    Options:
        -u, --url=URL        The URL of Elasticsearch.
        -i, --index=INDEX    The name of the Elasticsearch index to use.
        -d, --dry            Dry run the janitor task.
        -t, --to-daemon      Index records by adding them to the indexer daemon's queue.
    """
    kwargs = {
        'es_url': args.get('--url'),
        'es_index': args.get('--index'),
        'dry': bool(args['--dry']),
        'to_daemon': bool(args['--to-daemon']),
    }

    if args['--async']:
        tasks.elasticsearch_janitor.apply_async((), kwargs)
    else:
        tasks.elasticsearch_janitor(**kwargs)
Esempio n. 5
0
    def test_date_created(self, elastic, no_celery):
        fake, real = [], []

        for i in range(1, 6):
            fake.append(IndexableWorkTestHelper(elastic, index=False, date=pendulum.now()))
            real.append(IndexableWorkTestHelper(elastic, index=False, date=pendulum.now().add(days=-i)))
        real.append(IndexableWorkTestHelper(elastic, index=False, date=pendulum.now().add(days=-i)))

        index_helpers(*fake)

        for helper in fake:
            helper.assert_indexed()
            helper.work.administrative_change(is_deleted=True)

        for helper in real:
            helper.assert_not_indexed()

        tasks.elasticsearch_janitor(to_daemon=False)

        for helper in real:
            helper.assert_indexed()
Esempio n. 6
0
def janitor(args, argv):
    """
    Usage: {0} search janitor [--dry | --async] [options]

    Options:
        -u, --url=URL        The URL of Elasticsearch.
        -i, --index=INDEX    The name of the Elasticsearch index to use.
        -d, --dry            Dry run the janitor task.
        -t, --to-daemon      Index records by adding them to the indexer daemon's queue.
    """
    kwargs = {
        'es_url': args.get('--url'),
        'es_index': args.get('--index'),
        'dry': bool(args['--dry']),
        'to_daemon': bool(args['--to-daemon']),
    }

    if args['--async']:
        tasks.elasticsearch_janitor.apply_async((), kwargs)
    else:
        tasks.elasticsearch_janitor(**kwargs)