Ver código fonte

Tests passing

Ask Solem 12 anos atrás
pai
commit
60b8dba05e

+ 36 - 19
celery/bin/celery.py

@@ -12,8 +12,8 @@ from pprint import pformat
 from celery import __version__
 from celery.platforms import EX_OK, EX_FAILURE, EX_UNAVAILABLE, EX_USAGE
 from celery.utils import term
+from celery.utils import text
 from celery.utils.imports import symbol_by_name
-from celery.utils.text import pluralize
 from celery.utils.timeutils import maybe_iso8601
 
 from celery.bin.base import Command as BaseCommand, Option
@@ -40,8 +40,9 @@ class Error(Exception):
         return self.reason
 
 
-def command(fun, name=None):
+def command(fun, name=None, sortpri=0):
     commands[name or fun.__name__] = fun
+    fun.sortpri = sortpri
     return fun
 
 
@@ -113,18 +114,19 @@ class Command(BaseCommand):
         c = self.colored
         try:
             return (c.green("OK"),
-                    indent(self.prettify(n["ok"])[1]))
+                    text.indent(self.prettify(n["ok"])[1], 4))
         except KeyError:
             pass
         return (c.red("ERROR"),
-                indent(self.prettify(n["error"])[1]))
+                text.indent(self.prettify(n["error"])[1], 4))
 
     def say_remote_command_reply(self, replies):
         c = self.colored
         node = replies.keys()[0]
         reply = replies[node]
         status, preply = self.prettify(reply)
-        self.say_chat("->", c.cyan(node, ": ") + status, indent(preply))
+        self.say_chat("->", c.cyan(node, ": ") + status,
+                      text.indent(preply, 4))
 
     def prettify(self, n):
         OK = str(self.colored.green("OK"))
@@ -172,10 +174,24 @@ def create_delegate(name, Command):
                                              "__module__": __name__}))
 
 
-worker = create_delegate("worker", "celery.bin.celeryd:WorkerCommand")
-events = create_delegate("events", "celery.bin.celeryev:EvCommand")
-beat = create_delegate("beat", "celery.bin.celerybeat:BeatCommand")
-amqp = create_delegate("amqp", "celery.bin.camqadm:AMQPAdminCommand")
+class worker(Delegate):
+    Command = "celery.bin.celeryd:WorkerCommand"
+worker = command(worker, sortpri=01)
+
+
+class events(Delegate):
+    Command = "celery.bin.celeryd:WorkerCommand"
+events = command(events, sortpri=10)
+
+
+class beat(Delegate):
+    Command = "celery.bin.celerybeat:BeatCommand"
+beat = command(beat, sortpri=20)
+
+
+class amqp(Delegate):
+    Command = "celery.bin.camqadm:AMQPAdminCommand"
+amqp = command(amqp, sortpri=30)
 
 
 class list_(Command):
@@ -263,11 +279,11 @@ class purge(Command):
         messages_removed = self.app.control.purge()
         if messages_removed:
             self.out("Purged %s %s from %s known task %s." % (
-                messages_removed, pluralize(messages_removed, "message"),
-                queues, pluralize(queues, "queue")))
+                messages_removed, text.pluralize(messages_removed, "message"),
+                queues, text.pluralize(queues, "queue")))
         else:
             self.out("No messages purged from %s known %s" % (
-                queues, pluralize(queues, "queue")))
+                queues, text.pluralize(queues, "queue")))
 purge = command(purge)
 
 
@@ -359,10 +375,6 @@ class inspect(Command):
 inspect = command(inspect)
 
 
-def indent(s, n=4):
-    return "\n".join(" " * n + l for l in s.split("\n"))
-
-
 class status(Command):
     option_list = inspect.option_list
 
@@ -377,7 +389,7 @@ class status(Command):
         nodecount = len(replies)
         if not kwargs.get("quiet", False):
             self.out("\n%s %s online." % (nodecount,
-                                          pluralize(nodecount, "node")))
+                                          text.pluralize(nodecount, "node")))
 status = command(status)
 
 
@@ -494,6 +506,12 @@ class shell(Command):  # pragma: no cover
 shell = command(shell)
 
 
+def commandlist(indent=0):
+    return (text.indent(command, indent)
+                for command in sorted(commands,
+                    key=lambda k: commands[k].sortpri or k))
+
+
 class help(Command):
 
     def usage(self, command):
@@ -502,8 +520,7 @@ class help(Command):
     def run(self, *args, **kwargs):
         self.parser.print_help()
         self.out(HELP % {"prog_name": self.prog_name,
-                         "commands": "\n".join(indent(command)
-                                             for command in sorted(commands))})
+                         "commands": "\n".join(commandlist(ident=4))})
 
         return EX_USAGE
 help = command(help)

+ 1 - 1
celery/tests/worker/test_worker.py

@@ -796,7 +796,7 @@ class test_WorkController(AppCase):
         self.assertTrue(app.loader.init_worker.call_count)
         self.assertTrue(on_worker_process_init.called)
         self.assertIs(_tls.current_app, app)
-        set_mp_process_title.assert_called_with("celeryd",
+        set_mp_process_title.assert_called_with("celery",
                         hostname="awesome.worker.com")
 
     def test_with_rate_limits_disabled(self):

+ 3 - 237
docs/community.rst

@@ -1,7 +1,7 @@
 .. _community:
 
 =======================
-  Community Resources
+Community Resources
 =======================
 
 This is a list of external blog posts, tutorials and slides related
@@ -46,244 +46,10 @@ http://blog.gmane.org/gmane.comp.python.amqp.celery.user
 
 .. _res-irc-logs:
 
-IRC Logs
---------
-
-http://botland.oebfare.com/logger/celery/
-
 .. _community-news:
 
 News
 ====
 
-Celery: Mini Tutorial (Catalan)
--------------------------------
-http://trespams.com/2010/11/28/celery-mini-tutorial/
-
-Building a Django App Server with Chef
---------------------------------------
-http://ericholscher.com/blog/2010/nov/11/building-django-app-server-chef-part-4/
-
-Introducció a Celery (Catalan)
-------------------------------
-http://trespams.com/2010/11/13/introduccio-celery/
-
-Django and Celery - Death to Cron
----------------------------------
-http://tensixtyone.com/django-and-celery-death-to-cron
-
-Celery Tips
------------
-http://ericholscher.com/blog/2010/nov/2/celery-tips/
-
-What's your favorite Django app?
---------------------------------
-http://jacobian.org/writing/favorite-apps/
-
-Virtualenv Tips
----------------
-http://ericholscher.com/blog/2010/nov/1/virtualenv-tips/
-
-10 Tools That Make Django Better
---------------------------------
-http://iamseb.com/seb/2010/10/10-django-tools/
-
-Distributed Task Locking in Celery
-----------------------------------
-http://www.loose-bits.com/2010_10_10_archive.html
-
-Celery — распределенные очереди задач на Python (Russian)
----------------------------------------------------------
-http://www.bitbybit.ru/article/216
-
-Подробнее о Celery (Russian)
-----------------------------
-http://vorushin.ru/blog/34-celery-described/
-
-Celery, RabbitMQ and sending messages directly.
------------------------------------------------
-http://blog.timc3.com/2010/10/17/celery-rabbitmq-and-sending-messages-directly/
-
-Cron dentro do Django com Celery (Portugese)
---------------------------------------------
-http://blog.avelino.us/2010/10/cron-dentro-do-django-com-celery.html
-
-RabbitMQとCeleryを使ってDjangoでジョブキューしてみる (Japanese)
----------------------------------------------------------------
-http://d.hatena.ne.jp/yuku_t/
-
-Kaninchen & Schlangen: RabbitMQ & Python (German)
--------------------------------------------------
-http://www.scribd.com/doc/37562923/Kaninchen-Schlangen-RabbitMQ-Python
-
-Celery - Eine asynchrone Task Queue (nicht nur) für Django (German)
--------------------------------------------------------------------
-http://www.scribd.com/doc/39203296/Celery-Eine-asynchrone-Task-Queue-nicht-nur-fur-Django
-
-Asynchronous Processing Using Celery (historio.us)
---------------------------------------------------
-http://blog.historio.us/asynchronous-processing-using-celery
-
-"Massaging the Pony: Message Queues and You" (Djangocon 2010)
--------------------------------------------------------------
-http://www.slideshare.net/shawnrider/massaging-the-pony-message-queues-and-you
-
-"Large problems, Mostly Solved" (Djangocon 2010)
-------------------------------------------------
-http://www.slideshare.net/ericholscher/large-problems
-
-A Simple Celery with Django How-To
-----------------------------------
-http://shawnmilo.blogspot.com/2010/07/simple-celery-with-django-how-to.html
-
-Django and asynchronous jobs
-----------------------------
-http://www.davidfischer.name/2010/09/django-and-asynchronous-jobs/
-
-Celery: добавляем параллелизм в Django (Russian)
-------------------------------------------------
-http://www.proft.com.ua/2010/09/4/celery-dobavlyaem-parallelizm-v-django/
-
-Celery presentation at PyCon India 2010
----------------------------------------
-
-http://in.pycon.org/2010/talks/50-python-celery
-http://in.pycon.org/2010/static/files/talks/50/mahendra-celery-pycon-2010.pdf
-
-celery, django and virtualenv playing nice.
--------------------------------------------
-http://tumblr.whatupderek.com/post/1072002968/celery-django-and-virtualenv-playing-nice
-
-Django Task Queueing with Celery
---------------------------------
-http://justinvoss.wordpress.com/2010/06/22/django-task-queueing-with-celery/
-
-django-celery presentation at DJUGL 2010.
------------------------------------------
-
-http://www.slideshare.net/matclayton/django-celery
-
-.. raw:: html
-
-    <div style="width:425px" id="__ss_4848163"><strong style="display:block;
-    margin:12px 0 4px">
-    <a href="http://www.slideshare.net/matclayton/django-celery"
-    title="Django Celery ">Django Celery </a></strong>
-    <object id="__sse4848163" width="425" height="355">
-    <param name="movie"
-    value="http://static.slidesharecdn.com/swf/ssplayer2.swf?
-    doc=djangocelery1-100727052925-phpapp02&stripped_title=django-celery" />
-    <param name="allowFullScreen" value="true"/>
-    <param name="allowScriptAccess" value="always"/>
-    <embed name="__sse4848163"
-    src="http://static.slidesharecdn.com/swf/ssplayer2.swf?
-    doc=djangocelery1-100727052925-phpapp02&stripped_title=django-celery"
-    type="application/x-shockwave-flash" allowscriptaccess="always"
-    allowfullscreen="true" width="425" height="355"></embed></object>
-    <div style="padding:5px 0 12px">View more
-    <a href="http://www.slideshare.net/">presentations</a> from
-    <a href="http://www.slideshare.net/matclayton">Wakari Limited</a>.
-    </div></div>
-
-Django/Celery Quickstart (or, how I learned to stop using cron and love celery)
--------------------------------------------------------------------------------
-http://bitkickers.blogspot.com/2010/07/djangocelery-quickstart-or-how-i.html
-
-Using Python magic to improve the deferred API
-----------------------------------------------
-http://blog.notdot.net/2010/06/Using-Python-magic-to-improve-the-deferred-API
-
-How Celery, Carrot, and your messaging stack work
--------------------------------------------------
-http://jasonmbaker.com/how-celery-carrot-and-your-messaging-stack-wo
-
-Large Problems in Django, Mostly Solved: Delayed Execution
-----------------------------------------------------------
-http://ericholscher.com/blog/2010/jun/23/large-problems-django-mostly-solved-delayed-execut/
-
-Introduction to Celery
-----------------------
-
-Awesome slides from when `Idan Gazit`_ had a talk about Celery at `PyWeb-IL`_:
-http://www.slideshare.net/idangazit/an-introduction-to-celery
-
-.. _`Idan Gazit`: http://twitter.com/IdanGazit
-.. _`PyWeb-IL`: http://groups.google.com/group/pyweb-il
-
-.. raw:: html
-
-    <div style="width:425px;text-align:left" id="__ss_2089054">
-    <a style="font:14px Helvetica,Arial,Sans-serif;display:block;
-    margin:12px 0 3px 0;text-decoration:underline;"
-    href="http://www.slideshare.net/idangazit/an-introduction-to-celery"
-    title="An Introduction to Celery">An Introduction to Celery</a>
-    <object style="margin:0px" width="425" height="355"> <param name="movie"
-    value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pyweb-celery-090929081406-phpapp01&stripped_title=an-introduction-to-celery" />
-    <param name="allowFullScreen" value="true"/><param name="allowScriptAccess"
-    value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pyweb-celery-090929081406-phpapp01&stripped_title=an-introduction-to-celery" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355">
-    </embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more
-    <a style="text-decoration:underline;"
-    href="http://www.slideshare.net/">documents</a>
-    from <a style="text-decoration:underline;"
-    href="http://www.slideshare.net/idangazit">Idan Gazit</a>.</div></div>
-
-
-RabbitMQ, Celery and Django
----------------------------
-
-Great Celery tutorial by `Robert Pogorzelski`_ at his blog "Happy Stream of
-Thoughts":
-http://robertpogorzelski.com/blog/2009/09/10/rabbitmq-celery-and-django/
-
-.. _`Robert Pogorzelski`: http://robertpogorzelski.com/
-
-Message Queues, Django and Celery Quick Start
----------------------------------------------
-
-Celery tutorial by `Rich Leland`_, the installation section is Mac OS X
-specific:
-http://mathematism.com/2010/feb/16/message-queues-django-and-celery-quick-start/
-
-.. _`Rich Leland`: http://twitter.com/richleland
-
-Background task processing and deferred execution in Django
------------------------------------------------------------
-
-`Alon Swartz`_ writes about celery and RabbitMQ on his blog:
-    http://www.turnkeylinux.org/blog/django-celery-rabbitmq
-
-.. _`Alon Swartz`: http://twitter.com/alonswartz
-
-Build a processing queue [...] in less than a day using RabbitMQ and Celery
----------------------------------------------------------------------------
-
-Tutorial in 2 parts written by `Tim Bull`_:
-http://timbull.com/build-a-processing-queue-with-multi-threading
-
-.. _`Tim Bull`: http://twitter.com/timbull
-
-How to get celeryd to work on FreeBSD
--------------------------------------
-
-Installing multiprocessing on FreeBSD isn't that easy, but thanks to `Viktor Petersson`_
-we now have a step-to-step guide:
-http://www.playingwithwire.com/2009/10/how-to-get-celeryd-to-work-on-freebsd/
-
-.. _`Viktor Petersson`: http://twitter.com/vpetersson
-
-Web-based 3D animation software
--------------------------------
-
-Indy Chang Liu at `ThinkingCactus`_ uses Celery to render animations
-asynchronously (PDF):
-http://ojs.pythonpapers.org/index.php/tppm/article/viewFile/105/122
-
-.. _`ThinkingCactus`: http://thinkingcactus.com/
-
-Queued Storage Backend for Django
----------------------------------
-http://stepsandnumbers.com/archive/2010/01/04/queued-storage-backend-for-django/
-
-RabbitMQ with Python and Ruby
------------------------------
-http://www.slideshare.net/hungryblank/rabbitmq-with-python-and-ruby-rupy-2009
+This section has moved to the Celery homepage:
+http://celeryproject.org/community/

+ 1 - 1
docs/getting-started/next-steps.rst

@@ -124,7 +124,7 @@ by passing in the `--help` flag::
 
     $ celery worker --help
 
-These options are described in more detailed in the :ref:`Workers Guide <guide-worker>`.
+These options are described in more detailed in the :ref:`Workers Guide <guide-workers>`.
 
 .. sidebar:: About the :option:`--app` argument
 

+ 1 - 1
docs/userguide/overview.rst

@@ -39,7 +39,7 @@ a "task".
 
 Workers
 =======
-Go to :ref:`guide-worker`.
+Go to :ref:`guide-workers`.
 
 Monitoring
 ==========

+ 9 - 6
docs/userguide/workers.rst

@@ -1,4 +1,4 @@
-.. _guide-worker:
+.. _guide-workers:
 
 ===============
  Workers Guide
@@ -13,13 +13,15 @@
 Starting the worker
 ===================
 
-You can start the worker in the foreground by executing the command::
+.. sidebar:: Daemonizing
+
+    You probably want to use a daemonization tool to start
+    in the background.  See :ref:`daemonizing` for help
+    detaching the worker using popular daemonization tools.
 
-    $ celery worker --loglevel=INFO
+You can start the worker in the foreground by executing the command::
 
-You probably want to use a daemonization tool to start
-in the background.  See :ref:`daemonizing` for help
-detaching the worker using popular daemonization tools.
+    $ celery worker --loglevel=INFO --app=app
 
 For a full list of available command line options see
 :mod:`~celery.bin.celeryd`, or simply do::
@@ -226,6 +228,7 @@ Autoscaling
 ===========
 
 .. versionadded:: 2.2
+
 pool support: *processes*, *gevent*
 
 The *autoscaler* component is used to dynamically resize the pool