Skip to content

Commit 03d6d19

Browse files
committed
Merge branch 'release/0.4'
2 parents bc69cd2 + 6d97a58 commit 03d6d19

File tree

25 files changed

+809
-301
lines changed

25 files changed

+809
-301
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
tests/whoosh_index
44
*.egg
55
*.egg-info
6-
.tox
6+
.tox
7+
.coverage
8+
docs/_build

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Jannis Leidel <jannis@leidel.info>
2+
Daniel Lindsley

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include README.rst
22
include AUTHORS
3-
recursive-include tests *
3+
include tox.ini
4+
recursive-include tests *
5+
recursive-include docs *

README.rst

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Requirements
1010

1111
* Django 1.2+
1212
* Haystack_ `1.2.X`_ *or* `2.0.X`_
13-
* Celery_ 1.X
13+
* Celery_ 2.X
1414

1515
You also need to install your choice of one of the supported search engines
1616
for Haystack and one of the supported backends for Celery.
@@ -26,6 +26,16 @@ Use your favorite Python package manager to install the app from PyPI, e.g.::
2626

2727
pip install celery-haystack
2828

29+
By default a few dependencies will automatically be installed:
30+
31+
- django-appconf_ -- An app to gracefully handle application settings.
32+
33+
- versiontools_ -- A library to help staying compatible to `PEP 386`_.
34+
35+
.. _django-appconf: http://pypi.python.org/pypi/django-appconf
36+
.. _versiontools: http://pypi.python.org/pypi/versiontools
37+
.. _`PEP 386`: http://www.python.org/dev/peps/pep-0386/
38+
2939
Setup
3040
-----
3141

@@ -35,53 +45,6 @@ Setup
3545
``haystack.indexes.Indexable``).
3646
3. Ensure your Celery instance is running.
3747

38-
Changelog
39-
---------
40-
41-
0.3.1 (2011-08-22)
42-
^^^^^^^^^^^^^^^^^^
43-
44-
* Minor bugfix in new appconf support code.
45-
46-
0.3 (2011-08-22)
47-
^^^^^^^^^^^^^^^^
48-
49-
* Moved configuration defaults handling to django-appconf_.
50-
51-
* Fixed issue that occured when retrying a task.
52-
53-
.. _django-appconf: http://pypi.python.org/pypi/django-appconf
54-
55-
0.2.1 (2011-08-05)
56-
^^^^^^^^^^^^^^^^^^
57-
58-
* Fixed typo in exception message handling.
59-
60-
0.2 (2011-08-04)
61-
^^^^^^^^^^^^^^^^
62-
63-
* Added support for Haystack 1.2.X.
64-
65-
* Properly stop indexing if instance couldn't be found.
66-
67-
* Forced Celery task config values to be of the correct type.
68-
69-
0.1.2 (2011-07-29) and 0.1.3 (2011-08-01)
70-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71-
72-
* Removed stale print statement.
73-
74-
0.1.1 (2011-07-29)
75-
^^^^^^^^^^^^^^^^^^
76-
77-
* Fixed packaging issue (added manifest template).
78-
79-
80-
0.1 (2011-07-29)
81-
^^^^^^^^^^^^^^^^
82-
83-
* Initial release.
84-
8548
Thanks
8649
------
8750

@@ -92,3 +55,11 @@ queues_ library by Matt Croyden.
9255
.. _queued_search: https://github.com/toastdriven/queued_search/
9356
.. _Celery: http://celeryproject.org/
9457
.. _queues: http://code.google.com/p/queues/
58+
59+
Issues
60+
------
61+
62+
Please use the `Github issue tracker`_ for any bug reports or feature
63+
requests.
64+
65+
.. _`Github issue tracker`: https://github.com/ennio/celery-haystack/issues

celery_haystack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# following PEP 386, versiontools will pick it up
2-
__version__ = (0, 3, 1, "final", 0)
2+
__version__ = (0, 4, 0, "final", 0)

celery_haystack/conf.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from django.conf import settings
2+
from haystack import constants
3+
from appconf import AppConf
4+
5+
6+
class CeleryHaystack(AppConf):
7+
DEFAULT_ALIAS = None
8+
RETRY_DELAY = 5 * 60
9+
MAX_RETRIES = 1
10+
DEFAULT_TASK = 'celery_haystack.tasks.CeleryHaystackSignalHandler'
11+
12+
COMMAND_BATCH_SIZE = None
13+
COMMAND_AGE = None
14+
COMMAND_REMOVE = False
15+
COMMAND_WORKERS = 0
16+
COMMAND_APPS = []
17+
COMMAND_VERBOSITY = 1
18+
19+
def configure_default_alias(self, value):
20+
return value or getattr(constants, 'DEFAULT_ALIAS', None)
21+
22+
def configure(self):
23+
data = {}
24+
for name, value in self.configured_data.items():
25+
if name in ('RETRY_DELAY', 'MAX_RETRIES',
26+
'COMMAND_WORKERS', 'COMMAND_VERBOSITY'):
27+
value = int(value)
28+
data[name] = value
29+
return data

celery_haystack/indexes.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
from django.db.models import signals
22

3-
from haystack import constants, indexes
3+
from haystack import indexes
44
from haystack.utils import get_identifier
55

66
from celery_haystack.utils import get_update_task
77

8-
from appconf import AppConf
9-
10-
11-
class CeleryHaystack(AppConf):
12-
DEFAULT_ALIAS = None
13-
RETRY_DELAY = 5 * 60
14-
MAX_RETRIES = 1
15-
DEFAULT_TASK = 'celery_haystack.tasks.CeleryHaystackSignalHandler'
16-
17-
COMMAND_BATCH_SIZE = None
18-
COMMAND_AGE = None
19-
COMMAND_REMOVE = False
20-
COMMAND_WORKERS = 0
21-
COMMAND_APPS = []
22-
COMMAND_VERBOSITY = 1
23-
24-
def configure_default_alias(self, value):
25-
return value or getattr(constants, 'DEFAULT_ALIAS', None)
26-
27-
def configure(self):
28-
data = {}
29-
for name, value in self.configured_data.items():
30-
if name in ('RETRY_DELAY', 'MAX_RETRIES',
31-
'COMMAND_WORKERS', 'COMMAND_VERBOSITY'):
32-
value = int(value)
33-
data[name] = value
34-
return data
35-
368

379
class CelerySearchIndex(indexes.SearchIndex):
3810
"""

celery_haystack/tasks.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from django.conf import settings
21
from django.core.exceptions import ImproperlyConfigured
32
from django.core.management import call_command
43
from django.db.models.loading import get_model
54

65
from celery.task import Task
6+
from celery_haystack.conf import settings
77

88
try:
99
from haystack import connections
@@ -88,10 +88,8 @@ def get_index(self, model_class, **kwargs):
8888
logger.error("Couldn't find a SearchIndex for %s." % model_class)
8989
return None
9090

91-
def get_handler_options(self, instance, **kwargs):
92-
options = {
93-
'instance': instance,
94-
}
91+
def get_handler_options(self, **kwargs):
92+
options = {}
9593
if legacy:
9694
options['using'] = self.using
9795
return options
@@ -111,31 +109,42 @@ def run(self, action, identifier, **kwargs):
111109

112110
# Then get the model class for the object path
113111
model_class = self.get_model_class(object_path, **kwargs)
114-
# and the instance of the model class with the pk
115-
instance = self.get_instance(model_class, pk, **kwargs)
116-
if instance is None:
117-
logger.debug("Didn't update index for '%s'" % identifier)
112+
current_index = self.get_index(model_class, **kwargs)
113+
114+
if action == 'delete':
115+
# If the object is gone, we'll use just the identifier against the
116+
# index.
117+
try:
118+
handler_options = self.get_handler_options(**kwargs)
119+
current_index.remove_object(identifier, **handler_options)
120+
except Exception, exc:
121+
logger.error(exc)
122+
self.retry([action, identifier], kwargs, exc=exc)
123+
else:
124+
logger.debug("Deleted '%s' from index" % identifier)
118125
return
119126

120-
# Call the appropriate handler of the current index and
121-
# handle exception if neccessary
122-
logger.debug("Indexing '%s'." % instance)
123-
try:
124-
current_index = self.get_index(model_class, **kwargs)
125-
handlers = {
126-
'update': current_index.update_object,
127-
'delete': current_index.remove_object,
128-
}
129-
handler_options = self.get_handler_options(instance, **kwargs)
130-
handlers[action](**handler_options)
131-
except KeyError, exc:
127+
elif action == 'update':
128+
# and the instance of the model class with the pk
129+
instance = self.get_instance(model_class, pk, **kwargs)
130+
if instance is None:
131+
logger.debug("Didn't update index for '%s'" % identifier)
132+
return
133+
134+
# Call the appropriate handler of the current index and
135+
# handle exception if neccessary
136+
logger.debug("Indexing '%s'." % instance)
137+
try:
138+
handler_options = self.get_handler_options(**kwargs)
139+
current_index.update_object(instance, **handler_options)
140+
except Exception, exc:
141+
logger.error(exc)
142+
self.retry([action, identifier], kwargs, exc=exc)
143+
else:
144+
logger.debug("Updated index with '%s'" % instance)
145+
else:
132146
logger.error("Unrecognized action '%s'. Moving on..." % action)
133147
self.retry([action, identifier], kwargs, exc=exc)
134-
except Exception, exc:
135-
logger.error(exc)
136-
self.retry([action, identifier], kwargs, exc=exc)
137-
else:
138-
logger.debug("Updated index with '%s'" % instance)
139148

140149

141150
class CeleryHaystackUpdateIndex(Task):

celery_haystack/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import sys
2-
3-
from django.conf import settings
41
from django.core.exceptions import ImproperlyConfigured
5-
from django.utils.functional import SimpleLazyObject
62
from django.utils.importlib import import_module
73

4+
from celery_haystack.conf import settings
5+
86

97
def get_update_task(task_path=None):
108
import_path = task_path or settings.CELERY_HAYSTACK_DEFAULT_TASK

0 commit comments

Comments
 (0)