Browse Source

Implement a management command for celeryd to have your full project environment within the daemon

gregoire 16 years ago
parent
commit
9dceb609fa

+ 17 - 14
celery/bin/celeryd.py

@@ -82,28 +82,31 @@ def main(concurrency=DAEMON_CONCURRENCY, daemon=False,
                             e.__class__, e, traceback.format_exc()))
 
 
-def parse_options(arguments):
-    parser = optparse.OptionParser()
-    parser.add_option('-c', '--concurrency', default=DAEMON_CONCURRENCY,
+option_list = (
+    optparse.make_option('-c', '--concurrency', default=DAEMON_CONCURRENCY,
             action="store", dest="concurrency", type="int",
-            help="Number of child processes processing the queue.")
-    parser.add_option('-f', '--logfile', default=DAEMON_LOG_FILE,
+            help="Number of child processes processing the queue."),
+    optparse.make_option('-f', '--logfile', default=DAEMON_LOG_FILE,
             action="store", dest="logfile",
-            help="Path to log file.")
-    parser.add_option('-l', '--loglevel', default=DAEMON_LOG_LEVEL,
+            help="Path to log file."),
+    optparse.make_option('-l', '--loglevel', default=DAEMON_LOG_LEVEL,
             action="store", dest="loglevel",
-            help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL/FATAL.")
-    parser.add_option('-p', '--pidfile', default=DAEMON_PID_FILE,
+            help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL/FATAL."),
+    optparse.make_option('-p', '--pidfile', default=DAEMON_PID_FILE,
             action="store", dest="pidfile",
-            help="Path to pidfile.")
-    parser.add_option('-w', '--wakeup-after', default=QUEUE_WAKEUP_AFTER,
+            help="Path to pidfile."),
+    optparse.make_option('-w', '--wakeup-after', default=QUEUE_WAKEUP_AFTER,
             action="store", dest="queue_wakeup_after",
             help="If the queue is empty, this is the time *in seconds* the "
                  "daemon sleeps until it wakes up to check if there's any "
-                 "new messages on the queue.")
-    parser.add_option('-d', '--daemon', default=False,
+                 "new messages on the queue."),
+    optparse.make_option('-d', '--daemon', default=False,
             action="store_true", dest="daemon",
-            help="Run in the background as a daemon.")
+            help="Run in the background as a daemon."),
+)
+
+def parse_options(arguments):
+    parser = optparse.OptionParser(option_list=option_list)
     options, values = parser.parse_args(arguments)
     if not isinstance(options.loglevel, int):
         options.loglevel = LOG_LEVELS[options.loglevel.upper()]

+ 0 - 0
celery/management/__init__.py


+ 0 - 0
celery/management/commands/__init__.py


+ 18 - 0
celery/management/commands/celeryd.py

@@ -0,0 +1,18 @@
+from django.core.management.base import BaseCommand
+
+from celery.bin.celeryd import main, option_list
+from celery.conf import LOG_LEVELS
+
+class Command(BaseCommand):
+    option_list = BaseCommand.option_list + option_list
+    help = 'Run the celery daemon'
+
+    def handle(self, *args, **options):
+        if not isinstance(options.get('loglevel'), int):
+            options['loglevel'] = LOG_LEVELS[options.get('loglevel').upper()]
+        main(concurrency=options.get('concurrency'),
+             daemon=options.get('daemon'),
+             logfile=options.get('logfile'),
+             loglevel=options.get('loglevel'),
+             pidfile=options.get('pidfile'),
+             queue_wakeup_after=options.get('queue_wakeup_after'))