FAQ 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ============================
  2. Frequently Asked Questions
  3. ============================
  4. Questions
  5. =========
  6. MySQL is throwing deadlock errors, what can I do?
  7. -------------------------------------------------
  8. **Answer:** MySQL has default isolation level set to ``REPEATABLE-READ``,
  9. if you don't really need that, set it to ``READ-COMMITTED``.
  10. You can do that by adding the following to your ``my.cnf``::
  11. [mysqld]
  12. transaction-isolation = READ-COMMITTED
  13. For more information about InnoDBs transaction model see `MySQL - The InnoDB
  14. Transaction Model and Locking`_ in the MySQL user manual.
  15. (Thanks to Honza Kral and Anton Tsigularov for this solution)
  16. .. _`MySQL - The InnoDB Transaction Model and Locking`: http://dev.mysql.com/doc/refman/5.1/en/innodb-transaction-model.html
  17. celeryd is not doing anything, just hanging
  18. --------------------------------------------
  19. **Answer:** See `MySQL is throwing deadlock errors, what can I do?`_.
  20. or `Why is Task.delay/apply\* just hanging?`.
  21. Why is Task.delay/apply\* just hanging?`
  22. ----------------------------------------
  23. **Answer:** :mod:`amqplib` hangs if it isn't able to authenticate to the
  24. AMQP server, so make sure you are able to access the configured vhost using
  25. the user and password.
  26. Why won't celeryd run on FreeBSD?
  27. ---------------------------------
  28. **Answer:** multiprocessing.Pool requires a working POSIX semaphore
  29. implementation which isn't enabled in FreeBSD by default. You have to enable
  30. POSIX semaphores in the kernel and manually recompile multiprocessing.
  31. I'm having ``IntegrityError: Duplicate Key`` errors. Why?
  32. ----------------------------------------------------------
  33. **Answer:** See `MySQL is throwing deadlock errors, what can I do?`_.
  34. Thanks to howsthedotcom.
  35. Why won't my Task run?
  36. ----------------------
  37. **Answer:** Did you register the task in the applications ``tasks.py`` module?
  38. (or in some other module Django loads by default, like ``models.py``?).
  39. Also there might be syntax errors preventing the tasks module being imported.
  40. You can find out if the celery daemon is able to run the task by executing the
  41. task manually:
  42. >>> from myapp.tasks import MyPeriodicTask
  43. >>> MyPeriodicTask.delay()
  44. Watch celery daemons logfile (or output if not running as a daemon), to see
  45. if it's able to find the task, or if some other error is happening.
  46. Why won't my Periodic Task run?
  47. -------------------------------
  48. **Answer:** See `Why won't my Task run?`_.
  49. How do I discard all waiting tasks?
  50. ------------------------------------
  51. **Answer:** Use ``celery.task.discard_all()``, like this:
  52. >>> from celery.task import discard_all
  53. >>> discard_all()
  54. 1753
  55. The number ``1753`` is the number of messages deleted.
  56. You can also start celeryd with the ``--discard`` argument which will
  57. accomplish the same thing.
  58. I've discarded messages, but there are still messages left in the queue?
  59. ------------------------------------------------------------------------
  60. **Answer:** Tasks are acknowledged (removed from the queue) as soon
  61. as they are actually executed. After the worker has received a task, it will
  62. take some time until it is actually executed, especially if there are a lot
  63. of tasks already waiting for execution. Messages that are not acknowledged are
  64. hold on to by the worker until it closes the connection to the broker (AMQP
  65. server). When that connection is closed (e.g because the worker was stopped)
  66. the tasks will be re-sent by the broker to the next available worker (or the
  67. same worker when it has been restarted), so to properly purge the queue of
  68. waiting tasks you have to stop all the workers, and then discard the tasks
  69. using ``discard_all``.
  70. Can I send some tasks to only some servers?
  71. --------------------------------------------
  72. **Answer:** As of now there is only one use-case that works like this,
  73. and that is tasks of type ``A`` can be sent to servers ``x`` and ``y``,
  74. while tasks of type ``B`` can be sent to server ``z``. One server can't
  75. handle more than one routing_key, but this is coming in a later release.
  76. Say you have two servers, ``x``, and ``y`` that handles regular tasks,
  77. and one server ``z``, that only handles feed related tasks, you can use this
  78. configuration:
  79. * Servers ``x`` and ``y``: settings.py:
  80. .. code-block:: python
  81. AMQP_SERVER = "rabbit"
  82. AMQP_PORT = 5678
  83. AMQP_USER = "myapp"
  84. AMQP_PASSWORD = "secret"
  85. AMQP_VHOST = "myapp"
  86. CELERY_AMQP_CONSUMER_QUEUE = "regular_tasks"
  87. CELERY_AMQP_EXCHANGE = "tasks"
  88. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  89. CELERY_AMQP_CONSUMER_ROUTING_KEY = "task.#"
  90. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  91. * Server ``z``: settings.py:
  92. .. code-block:: python
  93. AMQP_SERVER = "rabbit"
  94. AMQP_PORT = 5678
  95. AMQP_USER = "myapp"
  96. AMQP_PASSWORD = "secret"
  97. AMQP_VHOST = "myapp"
  98. CELERY_AMQP_EXCHANGE = "tasks"
  99. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  100. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  101. # This is the settings different for this server:
  102. CELERY_AMQP_CONSUMER_QUEUE = "feed_tasks"
  103. CELERY_AMQP_CONSUMER_ROUTING_KEY = "feed.#"
  104. Now to make a Task run on the ``z`` server you need to set its
  105. ``routing_key`` attribute so it starts with the words ``"task.feed."``:
  106. .. code-block:: python
  107. from feedaggregator.models import Feed
  108. from celery.task import Task
  109. class FeedImportTask(Task):
  110. name = "import_feed"
  111. routing_key = "feed.importer"
  112. def run(self, feed_url):
  113. # something importing the feed
  114. Feed.objects.import_feed(feed_url)
  115. You can also override this using the ``routing_key`` argument to
  116. :func:`celery.task.apply_async`:
  117. >>> from celery.task import apply_async
  118. >>> from myapp.tasks import RefreshFeedTask
  119. >>> apply_async(RefreshFeedTask, args=["http://cnn.com/rss"],
  120. ... routing_key="feed.importer")