discovery.py 720 B

1234567891011121314151617181920212223242526
  1. """celery.discovery"""
  2. from django.conf import settings
  3. def autodiscover():
  4. """Include tasks for all applications in :setting:`INSTALLED_APPS`."""
  5. return filter(None, [find_related_module(app, "tasks")
  6. for app in settings.INSTALLED_APPS])
  7. def find_related_module(app, related_name):
  8. """Given an application name and a module name, tries to find that
  9. module in the application, and running handler' if it finds it.
  10. """
  11. try:
  12. module = __import__(app, {}, {}, [related_name])
  13. except ImportError:
  14. return None
  15. try:
  16. related_module = getattr(module, related_name)
  17. except AttributeError:
  18. return None
  19. return related_module