diff --git a/opbeans/tasks.py b/opbeans/tasks.py index 8c0bf6a..90fb906 100644 --- a/opbeans/tasks.py +++ b/opbeans/tasks.py @@ -3,24 +3,26 @@ from django.core.cache import cache from django.db import models as m -from celery.decorators import task +import elasticapm from elasticsearch import TransportError from elasticsearch.helpers import bulk from elasticsearch_dsl import Search from elasticsearch_dsl.connections import connections from opbeans import utils, models, documents +from opbeans.celery import app - -@task() +@app.task() def update_stats(): if random.random() > 0.8: dict_for_truncation = {k: k for k in range(500)} assert False, "Bad luck!" + elasticapm.label(a="x", b="y") + elasticapm.set_custom_context({"a": "x", "b": "y"}) cache.set(utils.stats.cache_key, utils.stats(), 60) -@task() +@app.task() def sync_customers(): customer_docs = [] for customer in models.Customer.objects.annotate(total_orders=m.Count('orders')).order_by('pk')[50:]: @@ -28,7 +30,7 @@ def sync_customers(): bulk(connections.get_connection(), customer_docs) -@task() +@app.task() def sync_orders(): highest_id = None try: diff --git a/requirements.txt b/requirements.txt index f878898..963cabb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ Django==3.2.9 amqp==5.0.6 billiard==3.6.4.0 -celery==5.1.2 +celery==5.2.0 future==0.18.2 certifi dj-database-url==0.5.0 @@ -11,7 +11,7 @@ elasticsearch==7.15.1 elasticsearch-dsl==7.4.0 gunicorn==20.1.0 honcho==1.1.0 -kombu==5.1.0 +kombu==5.2.1 psycopg2-binary==2.9.1 pytz redis==3.5.3