celery-pylons / celerypylons / loader.py

from celery.loaders.base import BaseLoader
from pylons import config
import types

to_pylons = lambda x: x.replace('_','.').lower()
to_celery = lambda x: x.replace('.', '_').upper()

class PylonsSettingsProxy(object):
    Proxies settings from pylons.config
    def __getattr__(self, key):
        pylons_key = to_pylons(key)
            value = config[pylons_key]
            if len(value.split()) > 1: return value.split()
            return value
        except KeyError:
            raise AttributeError(pylons_key)
    def __setattr__(self, key, value):
        pylons_key = to_pylons(key)
        config[pylons_key] = value

class PylonsLoader(BaseLoader):
    Pylons celery loader.

        * Maps the celery config onto pylons.config

    def read_configuration(self):
        self.configured = True
        return PylonsSettingsProxy()

    def on_worker_init(self):
        Import task modules.
        # @@ Patch for when user only provides 1 module
        celery_imports = config.get('celery.imports', [])
        if isinstance(celery_imports, types.StringTypes):
            config['celery.imports'] = [celery_imports]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.