Commits

Anonymous committed 5ed3dc9

Seems everything is working now.

  • Participants
  • Parent commits d0e1f4a

Comments (0)

Files changed (3)

File celerypaste/__init__.py

 
     def read_configuration(self):
         config = dict(self._config)
-        init_tasks = config.pop("tasks", None) # XXX What is this?
         # this trips up django, and paste puts this in by default
         config.pop("__file__", None)
-        self.django_settings = self.setup_django_env(config)
-        return self.django_settings
+
+        # Can't import task modules yet, as the load has not been
+        # properly set up, so add custom import lists to the CELERY_IMPORTSe
+        # config, so the base loader can load them later.
+        task_modules = map(str.strip, config.pop("tasks", "").split(","))
+        imports = config.get("CELERY_IMPORTS", [])
+        config["CELERY_IMPORTS"] = imports + task_modules
+
+        return self.setup_django_env(config)
 
 
 class PasteLoaderFactory(object):
         return PasteLoader(self._config)
 
 
-def set_loader(config):
+def setup_loader(config):
     """
     order of operations is important
     """
-    os.environ[KEY_ENV_LOADER] = __name__
+    os.environ[KEY_ENV_LOADER] = "%s.Loader" % __name__
     os.environ["DJANGO_SETTINGS_MODULE"] = __name__ #why?
     _config={}
 
     def init_loader(self):
         paste_config = {}
         paste_config.update(self.get_config(self.parse_section()))
-        set_loader(paste_config)
+        setup_loader(paste_config)
 
     def parse_section(self):
         return self.options.section
                     os.path.sep,
                     config_file))
             else:
-                config = appconfig("config:%s" % config_file,
-                                   name = name,
-                                   relative_to = os.getcwd())
-                return config
+                return appconfig("config:%s" % config_file,
+                                 name=name,
+                                 relative_to=os.getcwd())
         else:
             raise BadCommand(self.parser.get_usage())
 
        $ paster celerysyncdb production.ini --section <section_name>
     """
 
+    summary = "Initialize celery database tables"
+
     def command(self):
         import sys
         self.init_loader()
        $ paster celeryd production.ini --section <section_name>
     """
 
-    def _get_celeryd_opts(self, config):
+    summary = "Celery worker"
+
+    def _get_celeryd_opts(self, config, prefix="celeryd."):
         """
         any option in the config prefixed with 'celeryd.' will be
         treated like command line arguments to celeryd
         """
-        celeryd_keys = []
-        result = {}
-        for k in config.keys():
-            if k.lower().startswith("celeryd."):
-                celeryd_keys.append(k)
-
-        for k in celeryd_keys:
-            result[k.replace("celeryd.", "")] = config.pop(k)
-
-        return result
+        return dict((k[len(prefix):], config.pop(k))
+                        for k in config.keys()
+                            if k.lower().startswith(prefix))
 
     def command(self):
         self.init_loader()
-[app:celery]
+[app:main]
 use=egg:celery-paste#app
 BROKER_HOST= localhost
 BROKER_PORT= 5672
-BROKER_VHOST= celeryTst
-BROKER_USER= celery
-BROKER_PASSWORD= celery
-CELERY_BACKEND= database
+BROKER_VHOST= /
+BROKER_USER= guest
+BROKER_PASSWORD= guest
+CELERY_BACKEND= amqp
 DATABASE_ENGINE= sqlite3
 DATABASE_NAME= %(here)s/test.db
-tasks=%(here)s/mytasks.py
+celeryd.loglevel= INFO
+tasks= mytasks

File tests/test_run.py

 import sys
 
-from celerypaste import set_loader
+from celerypaste import setup_loader
 
 CELERY_CONFIG = {"BROKER_HOST": "localhost",
                  "BROKER_PORT": 5672,
-                 "BROKER_VHOST": "celeryTst",
-                 "BROKER_USER": "celery",
-                 "BROKER_PASSWORD": "celery",
-                 "CELERY_BACKEND": "database",
+                 "BROKER_VHOST": "/",
+                 "BROKER_USER": "guest",
+                 "BROKER_PASSWORD": "guest",
+                 "CELERY_BACKEND": "amqp",
                  "DATABASE_ENGINE": "sqlite3",
                  "DATABASE_NAME": "test.db",
-                 "CELERY_IMPORTS": ("mytasks", )}
+                 "tasks": "mytasks",
+}
 
 
-set_loader(CELERY_CONFIG)
-
-from celery.task import Task
-
-
-class AddTask(Task):
-
-    def run(self, x, y):
-        return x+y
-
+setup_loader(CELERY_CONFIG)
 
 def setup_db():
     from celery.loaders import current_loader
 
 def test_run():
     setup_db()
-    result = AddTask.apply(args=[10, 10])
+    from mytasks import AddTask
+    result = AddTask.apply_async(args=[10, 10])
+    print("RESULT: %s" % result.get())
     assert result.get()==20, "didn't get expected result"
+
+if __name__ == "__main__":
+    test_run()