|
52 | 52 |
|
53 | 53 | new_contract("redis", lambda x: isinstance(x, (redis.Redis, redis.StrictRedis))) |
54 | 54 |
|
55 | | -try: |
56 | | - # Check whether a custom Celery configuration module named "snowplow_celery_config" exists |
57 | | - import snowplow_celery_config |
58 | | - app = Celery() |
59 | | - app.config_from_object(snowplow_celery_config) |
60 | | - |
61 | | -except ImportError: |
62 | | - # Otherwise configure Celery with default settings |
63 | | - app = Celery("Snowplow", broker="redis://guest@localhost//") |
64 | | - |
65 | 55 |
|
66 | 56 | class Emitter(object): |
67 | 57 | """ |
@@ -172,7 +162,6 @@ def reached_limit(self): |
172 | 162 | else: |
173 | 163 | return self.bytes_queued >= self.byte_limit or len(self.buffer) >= self.buffer_size |
174 | 164 |
|
175 | | - @task(name="Flush") |
176 | 165 | def flush(self): |
177 | 166 | """ |
178 | 167 | Sends all events in the buffer to the collector. |
@@ -393,16 +382,32 @@ class CeleryEmitter(Emitter): |
393 | 382 | Works like the base Emitter class, |
394 | 383 | but on_success and on_failure callbacks cannot be set. |
395 | 384 | """ |
| 385 | + celery_app = None |
| 386 | + |
396 | 387 | def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_size=None, byte_limit=None): |
397 | 388 | super(CeleryEmitter, self).__init__(endpoint, protocol, port, method, buffer_size, None, None, byte_limit) |
398 | 389 |
|
| 390 | + try: |
| 391 | + # Check whether a custom Celery configuration module named "snowplow_celery_config" exists |
| 392 | + import snowplow_celery_config |
| 393 | + self.celery_app = Celery() |
| 394 | + self.celery_app.config_from_object(snowplow_celery_config) |
| 395 | + except ImportError: |
| 396 | + # Otherwise configure Celery with default settings |
| 397 | + self.celery_app = Celery("Snowplow", broker="redis://guest@localhost//") |
| 398 | + |
| 399 | + self.async_flush = self.celery_app.task(self.async_flush) |
| 400 | + |
399 | 401 | def flush(self): |
400 | 402 | """ |
401 | 403 | Schedules a flush task |
402 | 404 | """ |
403 | | - super(CeleryEmitter, self).flush.delay() |
| 405 | + self.async_flush.delay() |
404 | 406 | logger.info("Scheduled a Celery task to flush the event queue") |
405 | 407 |
|
| 408 | + def async_flush(self): |
| 409 | + super(CeleryEmitter, self).flush() |
| 410 | + |
406 | 411 |
|
407 | 412 | class RedisEmitter(object): |
408 | 413 | """ |
|
0 commit comments