Skip to content

Commit 88cd291

Browse files
committed
Upgrade Celery to 4.x (close snowplow#210)
1 parent 73f4796 commit 88cd291

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"greenlet>=0.4.10,<1.0",
7979
"requests>=2.2.1,<3.0",
8080
"pycontracts>=1.7.6,<2.0",
81-
"celery>=3.1.11,<4.0",
81+
"celery>=4.0,<5.0",
8282
"gevent>=1.0.2,<2.0",
8383
"redis>=2.9.1,<3.0",
8484
"six>=1.9.0,<2.0"

snowplow_tracker/emitters.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from queue import Queue
3232

3333
from celery import Celery
34-
from celery.contrib.methods import task
3534
import redis
3635
import requests
3736
from contracts import contract, new_contract
@@ -57,9 +56,9 @@
5756
import snowplow_celery_config
5857
app = Celery()
5958
app.config_from_object(snowplow_celery_config)
60-
6159
except ImportError:
6260
# Otherwise configure Celery with default settings
61+
snowplow_celery_config = None
6362
app = Celery("Snowplow", broker="redis://guest@localhost//")
6463

6564

@@ -172,7 +171,6 @@ def reached_limit(self):
172171
else:
173172
return self.bytes_queued >= self.byte_limit or len(self.buffer) >= self.buffer_size
174173

175-
@task(name="Flush")
176174
def flush(self):
177175
"""
178176
Sends all events in the buffer to the collector.
@@ -387,6 +385,14 @@ def consume(self):
387385
self.queue.task_done()
388386

389387

388+
@app.task(bind=True, name='tasks.flush') # the self passed with bind can be used for on_fail/retrying
389+
def flush_emitter(self, emitter):
390+
try:
391+
emitter.flush()
392+
finally:
393+
logger.info("Flush called on emitter")
394+
395+
390396
class CeleryEmitter(Emitter):
391397
"""
392398
Uses a Celery worker to send HTTP requests asynchronously.
@@ -400,7 +406,7 @@ def flush(self):
400406
"""
401407
Schedules a flush task
402408
"""
403-
super(CeleryEmitter, self).flush.delay()
409+
flush_emitter.delay(self) # passes emitter (self - CeleryEmitter) to task
404410
logger.info("Scheduled a Celery task to flush the event queue")
405411

406412

0 commit comments

Comments
 (0)