FAQ 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. I'm having ``IntegrityError: Duplicate Key`` errors. Why?
  21. ----------------------------------------------------------
  22. **Answer:** See `MySQL is throwing deadlock errors, what can I do?`_.
  23. Thanks to howsthedotcom.
  24. Why won't my Task run?
  25. ----------------------
  26. **Answer:** Did you register the task in the applications ``tasks.py`` module?
  27. (or in some other module Django loads by default, like ``models.py``?).
  28. Also there might be syntax errors preventing the tasks module being imported.
  29. You can find out if the celery daemon is able to run the task by executing the
  30. task manually:
  31. >>> from myapp.tasks import MyPeriodicTask
  32. >>> MyPeriodicTask.delay()
  33. Watch celery daemons logfile (or output if not running as a daemon), to see
  34. if it's able to find the task, or if some other error is happening.
  35. Why won't my Periodic Task run?
  36. -------------------------------
  37. See `Why won't my Task run?`_.
  38. Can I send some tasks to only some servers?
  39. --------------------------------------------
  40. As of now there is only one use-case that works like this, and that is
  41. tasks of type ``A`` can be sent to servers ``x`` and ``y``, while tasks
  42. of type ``B`` can be sent to server ``z``. One server can't handle more than
  43. one routing_key, but this is coming in a later release.
  44. Say you have two servers, ``x``, and ``y`` that handles regular tasks,
  45. and one server ``z``, that only handles feed related tasks, you can use this
  46. configuration:
  47. * Servers ``x`` and ``y``: settings.py:
  48. .. code-block:: python
  49. AMQP_SERVER = "rabbit"
  50. AMQP_PORT = 5678
  51. AMQP_USER = "myapp"
  52. AMQP_PASSWORD = "secret"
  53. AMQP_VHOST = "myapp"
  54. CELERY_AMQP_CONSUMER_QUEUE = "regular_tasks"
  55. CELERY_AMQP_EXCHANGE = "tasks"
  56. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  57. CELERY_AMQP_CONSUMER_ROUTING_KEY = "task.#"
  58. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  59. * Server ``z``: settings.py:
  60. .. code-block:: python
  61. AMQP_SERVER = "rabbit"
  62. AMQP_PORT = 5678
  63. AMQP_USER = "myapp"
  64. AMQP_PASSWORD = "secret"
  65. AMQP_VHOST = "myapp"
  66. CELERY_AMQP_EXCHANGE = "tasks"
  67. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  68. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  69. # This is the settings different for this server:
  70. CELERY_AMQP_CONSUMER_QUEUE = "feed_tasks"
  71. CELERY_AMQP_CONSUMER_ROUTING_KEY = "feed.#"
  72. Now to make a Task run on the ``z`` server you need to set its
  73. ``routing_key`` attribute so it starts with the words ``"task.feed."``:
  74. .. code-block:: python
  75. from feedaggregator.models import Feed
  76. from celery.task import Task
  77. class FeedImportTask(Task):
  78. name = "import_feed"
  79. routing_key = "feed.importer"
  80. def run(self, feed_url):
  81. # something importing the feed
  82. Feed.objects.import_feed(feed_url)
  83. You can also override this using the ``routing_key`` argument to
  84. :func:`celery.task.apply_async`:
  85. >>> from celery.task import apply_async
  86. >>> from myapp.tasks import RefreshFeedTask
  87. >>> apply_async(RefreshFeedTask, args=["http://cnn.com/rss"],
  88. ... routing_key="feed.importer")