Updating a Haystack search index with Django + Celery

前端 未结 4 523
醉梦人生
醉梦人生 2021-01-30 22:27

In my Django project I am using Celery. I switched over a command from crontab to be a periodic task and it works well but it is just calling a method on a model. Is it possible

4条回答
  •  面向向阳花
    2021-01-30 22:40

    Also, since version 2 of the haystack you can call rebuild index from python as

    from haystack.management.commands import update_index, rebuild_index
    rebuild_index.Command().handle(interactive=False)
    

    Where the "interactive" would prevent haystack asking question if you really want to rebuild index. This is equivalent to --no-input command line option.

    If you use xapian as FTS backend please remember that multithreaded updates to index would result in DB Write Lock. So, the solution with celery-haystack package does attempt to spread index update into multiple workers (multiple thread) resulting in the lock with xapian.

提交回复
热议问题