tasks.py 975 Bytes
Newer Older
Patrick Kimber's avatar
Patrick Kimber committed
1 2 3 4 5
# -*- encoding: utf-8 -*-
import logging

from celery import task

6 7
from contact.search import ContactIndex
from search.search import SearchIndex
Patrick Kimber's avatar
Patrick Kimber committed
8

Patrick Kimber's avatar
Patrick Kimber committed
9

10 11 12
logger = logging.getLogger(__name__)


Patrick Kimber's avatar
Patrick Kimber committed
13
@task()
14
def rebuild_contact_index():
15 16 17 18 19
    logger.info("Drop and rebuild contact index...")
    index = SearchIndex(ContactIndex())
    count = index.rebuild()
    logger.info("Contact index rebuilt - {} records - complete".format(count))
    return count
20 21


22 23 24 25 26 27 28 29 30
@task()
def refresh_contact_index():
    logger.info("Refresh contact index...")
    index = SearchIndex(ContactIndex())
    count = index.refresh()
    logger.info("Contact index refreshed - {} records - complete".format(count))
    return count


31 32
@task()
def update_contact_index(pk):
33 34 35 36 37 38 39
    logger.info("Search index - update contact {}".format(pk))
    index = SearchIndex(ContactIndex())
    count = index.update(pk)
    logger.info(
        "Search index - updated contact {} ({} record)".format(pk, count)
    )
    return count