Skip to content

Commit a9a7592

Browse files
committed
Use celery rabbit queue for Haystack Elasticsearch upates
1 parent 49a099c commit a9a7592

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

docker-compose.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3'
1+
version: "3"
22

33
services:
44
app:
@@ -9,6 +9,7 @@ services:
99
depends_on:
1010
- db
1111
- elasticsearch
12+
- rabbitmq
1213
volumes:
1314
- ./data:/app-data
1415
- .:/app
@@ -26,6 +27,7 @@ services:
2627
- ENVIRONMENT=development
2728
- SENTRY_DSN=https://36d69cae4d76e0452f3fbdbb5019a279@o242378.ingest.sentry.io/5246237
2829
- GOOGLE_ANALYTICS_ID=G-T25P07Y7G2
30+
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq//
2931
ports:
3032
- "8000:8000"
3133
command: bin/wait-for-deps.sh python manage.py runserver 0.0.0.0:8000
@@ -53,6 +55,20 @@ services:
5355
ports:
5456
- 9200
5557

58+
cerebro:
59+
image: lmenezes/cerebro
60+
ports:
61+
- "8001:9000"
62+
63+
rabbitmq:
64+
image: rabbitmq:3.7.28
65+
volumes:
66+
- rabbitmq-data:/var/lib/rabbitmq/
67+
ports:
68+
- 5672:5672
69+
- 15672:15672
70+
5671
volumes:
5772
db-data:
5873
es-data:
74+
rabbitmq-data:

pombola/search/search_indexes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf import settings
22

33
from haystack import indexes
4+
from celery_haystack.indexes import CelerySearchIndex
45

56
from pombola.core import models as core_models
67

@@ -16,7 +17,7 @@
1617
# Note - these indexes could be specified in the individual apps, which might
1718
# well be cleaner.
1819

19-
class BaseIndex(indexes.SearchIndex):
20+
class BaseIndex(CelerySearchIndex):
2021
text = indexes.CharField(document=True, use_template=True)
2122

2223
class PersonIndex(BaseIndex, indexes.Indexable):

pombola/settings/base.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import sentry_sdk
1515
from sentry_sdk.integrations.django import DjangoIntegration
16+
from sentry_sdk.integrations.celery import CeleryIntegration
1617

1718
from urlparse import urlparse
1819

@@ -324,7 +325,13 @@
324325
}
325326

326327

327-
HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
328+
# HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
329+
HAYSTACK_SIGNAL_PROCESSOR = "celery_haystack.signals.CelerySignalProcessor"
330+
CELERY_HAYSTACK_TRANSACTION_SAFE = True
331+
CELERY_HAYSTACK_DEFAULT_ALIAS = None
332+
CELERY_HAYSTACK_RETRY_DELAY = 5 * 60
333+
CELERY_HAYSTACK_MAX_RETRIES = 1
334+
CELERY_HAYSTACK_DEFAULT_TASK = "celery_haystack.tasks.CeleryHaystackSignalHandler"
328335

329336
# Admin autocomplete
330337
AJAX_LOOKUP_CHANNELS = {
@@ -436,6 +443,7 @@
436443
# Pombola templates do {% load thumbnail %}
437444
"easy_thumbnails",
438445
"sorl.thumbnail",
446+
"celery_haystack",
439447
"haystack",
440448
"slug_helpers",
441449
"info",
@@ -683,12 +691,12 @@ def show_toolbar(request):
683691
if os.environ.get("SENTRY_DSN"):
684692
sentry_sdk.init(
685693
dsn=os.environ.get("SENTRY_DSN"),
686-
enable_tracing=True,
687-
integrations=[DjangoIntegration()],
694+
#enable_tracing=True,
695+
integrations=[DjangoIntegration(), CeleryIntegration()],
688696
environment=os.environ.get("ENVIRONMENT"),
689-
traces_sample_rate=os.environ.get("SENTRY_TRACES_SAMPLE_RATE", 1.0),
690-
profiles_sample_rate=os.environ.get("SENTRY_PROFILES_SAMPLE_RATE", 1.0),
697+
#traces_sample_rate=os.environ.get("SENTRY_TRACES_SAMPLE_RATE", 1.0),
698+
#profiles_sample_rate=os.environ.get("SENTRY_PROFILES_SAMPLE_RATE", 1.0),
691699
send_default_pii=True,
692700
)
693701

694-
DATA_UPLOAD_MAX_NUMBER_FIELDS=None
702+
DATA_UPLOAD_MAX_NUMBER_FIELDS = None

requirements.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,18 @@ anyjson==0.3.3
124124
audioread==1.0.3
125125
billiard==3.3.0.19
126126
bleach==3.3.0
127-
celery==3.1.17
127+
django-appconf==1.0.2
128+
celery==3.1.25
129+
celery-haystack==0.10
130+
kombu==3.0.37
128131
chardet==2.3.0
129132
cssselect==0.9.1
130133
django-bleach==0.5.2
131-
django-celery==3.1.16
134+
django-celery==3.1.17
132135
django-qmethod==0.0.3
133136
django-subdomain-instances==3.0.2
134137
django-tastypie==0.12.1
135138
html5lib==0.999
136-
kombu==3.0.24
137139
mechanize==0.4.6
138140
mimeparse==0.1.3
139141
mock==1.3.0
@@ -206,5 +208,6 @@ zipstream==1.1.4
206208
xlrd==1.2.0
207209

208210
# Sentry
209-
sentry-sdk[django]==1.39.2
211+
#sentry-sdk[django]==1.39.2
212+
sentry-sdk==0.14.3
210213

0 commit comments

Comments
 (0)