Anonymous avatar Anonymous committed 0d81528

Got the basics in -- config needs to read in *all* of the options that celery supports.

Comments (0)

Files changed (3)

celerypylons/commands.py

+import os
+import sys
+import warnings
 from paste.script.command import Command, BadCommand
-
+import paste.deploy
+from pylons import config
 
 __all__ = ['CeleryDaemonCommand'] #, 'CeleryBeatCommand', 'CAMQPAdminCommand', 'CeleryEventCommand']
 
 
+## @@ We have to do some rather odd bootstrapping in order to get
+## celery to load correctly.
+try:
+    path_to_ini_file = sys.argv[2]
+    conf = paste.deploy.appconfig('config:' + path_to_ini_file)
+    config.init_app(conf.global_conf,conf.local_conf)
+    if os.environ.get('CELERY_CONFIG_MODULE', None) is not None:
+        warnings.warn("'CELERY_CONFIG_MODULE' environment variable is already set but will be overridden by celery-pylons.")
+except ValueError:
+    ## @@ If the user just wants to see usage or docs, don't fail on configuration
+    pass
+except IndexError:
+    ## @@ No configuration was passed in
+    pass
+os.environ['CELERY_CONFIG_MODULE'] = 'celerypylons.config'
+
+
+## @@ We can now import celeryd since the configuration has been set.
+from celery.bin import celeryd
+
+
 class CeleryDaemonCommand(Command):
     """Start the celery worker
 
     This command starts the celery worker that uses a paste.deploy
     configuration file for the daemon and the worker configuration.
     """
-    min_args = 0
-    usage = 'CONFIG_FILE [start|stop|restart|status] [var=value]'
+    min_args = 1
+    min_args_error = "Please provide a paster config file as an argument."
+    usage = 'CONFIG_FILE [celeryd options...]'
     takes_config_file = 1
     summary = __doc__.splitlines()[0]
     description = "".join(__doc__.splitlines()[2:])
     requires_config_file = True
 
     parser = Command.standard_parser(quiet=True)
-
+    for x in celeryd.OPTION_LIST:
+        parser.add_option(x)
+        
     def command(self):
-        pass
+        options = celeryd.parse_options(sys.argv[3:])
+        return celeryd.run_worker(**vars(options))

celerypylons/config.py

+from pylons import config
+import re
+
+# We'll adopt a URI style broker def:
+# amqp://user:password@host:port/vhost
+BROKER_URI_PARSER = re.compile(
+    r"amqp://(?P<user>[^:]+):(?P<password>[^@]+)@(?P<host>[^:]+)(:(?P<port>[0-9]+))?/(?P<vhost>.+)")
+parts = re.match(BROKER_URI_PARSER, config.get('celery.broker.uri', ""))
+
+BROKER_HOST = parts and parts.groupdict()['host']
+BROKER_PORT = parts and parts.groupdict().get('port', 5984)
+BROKER_USER = parts and parts.groupdict()['user']
+BROKER_PASSWORD = parts and parts.groupdict()['password']
+BROKER_VHOST = parts and parts.groupdict()['vhost']
+
+CELERY_RESULT_BACKEND = config.get("celery.result.backend", "amqp")
+CELERYD_CONCURRENCY = config.get("celeryd.concurrency", 4)
+CELERY_IMPORTS = config.get('celery.imports', "").split()
Add a comment to this file

celerypylons/loader.py

Empty file removed.

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.