Coverage for gwcelery/__init__.py: 96%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-11-14 05:52 +0000

1"""Celery application initialization.""" 

2 

3import sys 

4 

5from celery import Celery 

6 

7from . import email, igwn_alert, kafka, sentry, voevent 

8from ._version import get_versions 

9from .conf import playground 

10 

11__all__ = ('app',) 

12 

13__version__ = get_versions()['version'] 

14del get_versions 

15 

16# Use redis broker, because it supports locks (and thus singleton tasks). 

17app = Celery(__name__, broker='redis://', config_source=playground) 

18"""Celery application object.""" 

19 

20# Register email, LVAlert and VOEvent subsystems. 

21email.install(app) 

22igwn_alert.install(app) 

23voevent.install(app) 

24kafka.install(app) 

25 

26# Register all tasks. 

27app.autodiscover_tasks([__name__]) 

28 

29# Customize configuration from environment variable. 

30app.config_from_envvar('CELERY_CONFIG_MODULE', silent=True) 

31 

32# Use the same URL for both the result backend and the broker. 

33app.conf['result_backend'] = app.conf.broker_url 

34 

35sentry.configure() 

36 

37 

38def main(argv=None): 

39 if argv is None: 

40 argv = sys.argv 

41 argv = argv[1:] # Strip off the script name; click doesn't want it. 

42 app.start(argv) # The application can take it from here!