def django_setup(settings_module=None):
    """Initialize Django if required, must be run before performing
    any task on spooler or mule.
    """
    from django.conf import settings, ENVIRONMENT_VARIABLE
    if settings.configured:
        return
    if settings_module:
        import os
        os.environ[ENVIRONMENT_VARIABLE] = settings_module
    try:
        from django import setup
    except ImportError:

        def setup():
            settings._setup()
    setup()
