Skip to content

Commit

Permalink
Merge branch 'release/0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Jun 13, 2015
2 parents 0387801 + 6953776 commit e3f5d33
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 48 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ celery_haystack/tests/whoosh_index
*.egg
*.egg-info
.coverage
docs/_build
docs/_build
build/
dist/
.eggs/
MANIFEST
45 changes: 21 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,34 @@ script:
- coverage run --branch --source=celery_haystack `which django-admin.py` test celery_haystack
- coverage report --omit=celery_haystack/test*
env:
- DJANGO="Django==1.4.13" HAYSTACK=v1
- DJANGO="Django==1.4.13" HAYSTACK=v2
- DJANGO="Django==1.5.8" HAYSTACK=v1
- DJANGO="Django==1.5.8" HAYSTACK=v2
- DJANGO="Django==1.6.5" HAYSTACK=v1
- DJANGO="Django==1.6.5" HAYSTACK=v2
- DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v1
- DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v2
- DJANGO="Django==1.4.20" HAYSTACK=v1
- DJANGO="Django==1.4.20" HAYSTACK=v2
- DJANGO="Django==1.7.8" HAYSTACK=v1
- DJANGO="Django==1.7.8" HAYSTACK=v2
- DJANGO="Django==1.8.2" HAYSTACK=v2
matrix:
exclude:
- env: DJANGO="Django==1.4.13" HAYSTACK=v1
- env: DJANGO="Django==1.4.20" HAYSTACK=v1
python: "3.3"
- env: DJANGO="Django==1.4.13" HAYSTACK=v2
- env: DJANGO="Django==1.4.20" HAYSTACK=v2
python: "3.3"
- env: DJANGO="Django==1.5.8" HAYSTACK=v1
python: "3.3"
- env: DJANGO="Django==1.6.5" HAYSTACK=v1
python: "3.3"
- env: DJANGO="Django==1.4.13" HAYSTACK=v1
python: "3.4"
- env: DJANGO="Django==1.4.13" HAYSTACK=v2
python: "3.4"
- env: DJANGO="Django==1.5.8" HAYSTACK=v1
- env: DJANGO="Django==1.4.20" HAYSTACK=v1
python: "3.4"
- env: DJANGO="Django==1.6.5" HAYSTACK=v1
- env: DJANGO="Django==1.4.20" HAYSTACK=v2
python: "3.4"
- env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v1
- env: DJANGO="Django==1.7.8" HAYSTACK=v1
python: "2.6"
- env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v2
- env: DJANGO="Django==1.7.8" HAYSTACK=v2
python: "2.6"
- env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v1
- env: DJANGO="Django==1.8.2" HAYSTACK=v1
python: "2.6"
- env: DJANGO="Django==1.8.2" HAYSTACK=v2
python: "2.6"
- env: DJANGO="Django==1.7.8" HAYSTACK=v1
python: "3.3"
- env: DJANGO="Django==1.7.8" HAYSTACK=v1
python: "3.4"
- env: DJANGO="Django==1.8.2" HAYSTACK=v1
python: "3.3"
- env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" HAYSTACK=v1
- env: DJANGO="Django==1.8.2" HAYSTACK=v1
python: "3.4"
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include AUTHORS
include README.rst
include LICENSE
include README.rst
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
celery-haystack
===============

.. image:: https://secure.travis-ci.org/jezdez/celery-haystack.png?branch=develop
.. image:: https://secure.travis-ci.org/django-haystack/celery-haystack.png?branch=develop
:alt: Build Status
:target: http://travis-ci.org/jezdez/celery-haystack
:target: http://travis-ci.org/django-haystack/celery-haystack

This Django app allows you to utilize Celery for automatically updating and
deleting objects in a Haystack_ search index.
Expand Down Expand Up @@ -40,7 +40,7 @@ By default a few dependencies will automatically be installed:
race conditions as described in `Celery's user guide`_."

.. _django-appconf: http://pypi.python.org/pypi/django-appconf
.. _`django-celery-transactions`: https://github.com/chrisdoble/django-celery-transactions
.. _`django-celery-transactions`: https://github.com/chrisdoble/django-celery-transactions
.. _`Celery's user guide`: http://celery.readthedocs.org/en/latest/userguide/tasks.html#database-transactions

Usage
Expand All @@ -51,7 +51,7 @@ Haystack 1.X

1. Add ``'celery_haystack'`` to the ``INSTALLED_APPS`` setting

::
.. code:: python
INSTALLED_APPS = [
# ..
Expand All @@ -61,7 +61,7 @@ Haystack 1.X
2. Alter all of your ``SearchIndex`` subclasses to inherit from
``celery_haystack.indexes.CelerySearchIndex``

::
.. code:: python
from haystack import site, indexes
from celery_haystack.indexes import CelerySearchIndex
Expand All @@ -79,7 +79,7 @@ Haystack 2.X

1. Add ``'celery_haystack'`` to the ``INSTALLED_APPS`` setting

::
.. code:: python
INSTALLED_APPS = [
# ..
Expand All @@ -88,15 +88,15 @@ Haystack 2.X
2. Enable the celery-haystack signal processor in the settings

::
.. code:: python
HAYSTACK_SIGNAL_PROCESSOR = 'celery_haystack.signals.CelerySignalProcessor'
3. Alter all of your ``SearchIndex`` subclasses to inherit from
``celery_haystack.indexes.CelerySearchIndex`` and
``haystack.indexes.Indexable``

::
.. code:: python
from haystack import indexes
from celery_haystack.indexes import CelerySearchIndex
Expand Down Expand Up @@ -127,4 +127,4 @@ Issues
Please use the `Github issue tracker`_ for any bug reports or feature
requests.

.. _`Github issue tracker`: https://github.com/jezdez/celery-haystack/issues
.. _`Github issue tracker`: https://github.com/django-haystack/celery-haystack/issues
2 changes: 1 addition & 1 deletion celery_haystack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.8'
__version__ = '0.9'


def version_hook(config):
Expand Down
11 changes: 11 additions & 0 deletions celery_haystack/conf.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
from django.conf import settings # noqa
from django.core.exceptions import ImproperlyConfigured
from haystack import constants, __version__ as haystack_version
from haystack.management.commands import update_index as cmd
from appconf import AppConf


class CeleryHaystack(AppConf):
#: The default alias to
DEFAULT_ALIAS = None
#: The delay (in seconds) before task will be executed (Celery countdown)
COUNTDOWN = 0
#: The delay (in seconds) after which a failed index is retried
RETRY_DELAY = 5 * 60
#: The number of retries that are done
MAX_RETRIES = 1
#: The default Celery task class
DEFAULT_TASK = 'celery_haystack.tasks.CeleryHaystackSignalHandler'
#: The name of the celery queue to use, or None for default
QUEUE = None
#: Whether the task should be handled transaction safe
TRANSACTION_SAFE = True

Expand All @@ -32,6 +37,12 @@ class CeleryHaystack(AppConf):
def configure_default_alias(self, value):
return value or getattr(constants, 'DEFAULT_ALIAS', None)

def configure_command_batch_size(self, value):
return value or getattr(cmd, 'DEFAULT_BATCH_SIZE', None)

def configure_command_age(self, value):
return value or getattr(cmd, 'DEFAULT_AGE', None)

def configure(self):
data = {}
for name, value in self.configured_data.items():
Expand Down
1 change: 0 additions & 1 deletion celery_haystack/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ def enqueue(self, action, instance, sender, **kwargs):
if action == 'update' and not index.should_update(instance):
continue
enqueue_task(action, instance)
return # Only enqueue instance once
11 changes: 5 additions & 6 deletions celery_haystack/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
else:
from celery.task import Task # noqa

from celery.utils.log import get_task_logger

logger = get_task_logger(__name__)


class CeleryHaystackSignalHandler(Task):
using = settings.CELERY_HAYSTACK_DEFAULT_ALIAS
Expand All @@ -36,7 +40,6 @@ def split_identifier(self, identifier, **kwargs):
bits = identifier.split('.')

if len(bits) < 2:
logger = self.get_logger(**kwargs)
logger.error("Unable to parse object "
"identifer '%s'. Moving on..." % identifier)
return (None, None)
Expand Down Expand Up @@ -64,7 +67,6 @@ def get_instance(self, model_class, pk, **kwargs):
"""
Fetch the instance in a standarized way.
"""
logger = self.get_logger(**kwargs)
instance = None
try:
instance = model_class._default_manager.get(pk=pk)
Expand Down Expand Up @@ -98,8 +100,6 @@ def run(self, action, identifier, **kwargs):
Trigger the actual index handler depending on the
given action ('update' or 'delete').
"""
logger = self.get_logger(**kwargs)

# First get the object path and pk (e.g. ('notes.note', 23))
object_path, pk = self.split_identifier(identifier, **kwargs)
if object_path is None or pk is None:
Expand Down Expand Up @@ -155,12 +155,11 @@ class CeleryHaystackUpdateIndex(Task):
command from Celery.
"""
def run(self, apps=None, **kwargs):
logger = self.get_logger(**kwargs)
defaults = {
'batchsize': settings.CELERY_HAYSTACK_COMMAND_BATCH_SIZE,
'age': settings.CELERY_HAYSTACK_COMMAND_AGE,
'remove': settings.CELERY_HAYSTACK_COMMAND_REMOVE,
'using': settings.CELERY_HAYSTACK_DEFAULT_ALIAS,
'using': [settings.CELERY_HAYSTACK_DEFAULT_ALIAS],
'workers': settings.CELERY_HAYSTACK_COMMAND_WORKERS,
'verbosity': settings.CELERY_HAYSTACK_COMMAND_VERBOSITY,
}
Expand Down
16 changes: 14 additions & 2 deletions celery_haystack/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
from django.db import connection

from haystack.utils import get_identifier

Expand All @@ -19,7 +20,7 @@ def get_update_task(task_path=None):
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a "%s" '
'class.' % (module, attr))
return Task
return Task()


def enqueue_task(action, instance):
Expand All @@ -28,4 +29,15 @@ def enqueue_task(action, instance):
model instance.
"""
identifier = get_identifier(instance)
get_update_task().delay(action, identifier)
kwargs = {}
if settings.CELERY_HAYSTACK_QUEUE:
kwargs['queue'] = settings.CELERY_HAYSTACK_QUEUE
if settings.CELERY_HAYSTACK_COUNTDOWN:
kwargs['countdown'] = settings.CELERY_HAYSTACK_COUNTDOWN
task = get_update_task()
if hasattr(connection, 'on_commit'):
connection.on_commit(
lambda: task.apply_async((action, identifier), {}, **kwargs)
)
else:
task.apply_async((action, identifier), {}, **kwargs)
26 changes: 24 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
Changelog
=========

v0.9 (2015-06-13)
-----------------

* Moved to Haystack GitHub org: https://github.com/django-haystack/celery-haystack

* Fix handling the default Haystack backend alias, making it a list.

* Added ``CELERY_HAYSTACK_QUEUE`` setting to define which Celery queue to use.

* Added ``CELERY_HAYSTACK_COUNTDOWN`` setting to define when to start the
indexing task after initially creating it.

* Stop returning after after enqueing in the Haystack router to support
multple routers.

* Optionally support using django-transaction-hooks for improved transaction
handling.

* Instantiate update task class correctly.

* Use Celery's task logger utility function.

v0.8 (2014-07-31)
-------------------
-----------------

* Fix bug when using multiple Haystack indizes

Expand Down Expand Up @@ -77,7 +99,7 @@ v0.6 (2012-06-27)
* Improved support for multiple search indexes as implemented by
Haystack 2.X. Many thanks to Germán M. Bravo (Kronuz).

.. _`django-celery-transactions`: https://github.com/chrisdoble/django-celery-transactions
.. _`django-celery-transactions`: https://github.com/chrisdoble/django-celery-transactions
.. _`Celery's user guide`: http://celery.readthedocs.org/en/latest/userguide/tasks.html#database-transactions

v0.5 (2012-05-23)
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ summary = An app for integrating Celery with Haystack.
description-file = README.rst
home-page = http://celery-haystack.rtfd.org/
project-url =
Github, https://github.com/jezdez/celery-haystack/
Github, https://github.com/django-haystack/celery-haystack/
classifier =
Development Status :: 4 - Beta
Environment :: Web Environment
Expand Down Expand Up @@ -39,3 +39,6 @@ extra_files =

[backwards_compat]
zip_safe = False

[wheel]
universal = 1

0 comments on commit e3f5d33

Please sign in to comment.