faq.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. Can I send some tasks to only some servers?
  25. --------------------------------------------
  26. As of now there is only one use-case that works like this, and that is
  27. tasks of type ``A`` can be sent to servers ``x`` and ``y``, while tasks
  28. of type ``B`` can be sent to server ``z``. One server can't handle more than
  29. one routing_key, but this is coming in a later release.
  30. Say you have two servers, ``x``, and ``y`` that handles regular tasks,
  31. and one server ``z``, that only handles feed related tasks, you can use this
  32. configuration:
  33. * Servers ``x`` and ``y``: settings.py:
  34. .. code-block:: python
  35. AMQP_SERVER = "rabbit"
  36. AMQP_PORT = 5678
  37. AMQP_USER = "myapp"
  38. AMQP_PASSWORD = "secret"
  39. AMQP_VHOST = "myapp"
  40. CELERY_AMQP_CONSUMER_QUEUE = "regular_tasks"
  41. CELERY_AMQP_EXCHANGE = "tasks"
  42. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  43. CELERY_AMQP_CONSUMER_ROUTING_KEY = "task.#"
  44. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  45. * Server ``z``: settings.py:
  46. .. code-block:: python
  47. AMQP_SERVER = "rabbit"
  48. AMQP_PORT = 5678
  49. AMQP_USER = "myapp"
  50. AMQP_PASSWORD = "secret"
  51. AMQP_VHOST = "myapp"
  52. CELERY_AMQP_CONSUMER_QUEUE = "feed_tasks"
  53. CELERY_AMQP_EXCHANGE = "tasks"
  54. CELERY_AMQP_PUBLISHER_ROUTING_KEY = "task.regular"
  55. CELERY_AMQP_CONSUMER_ROUTING_KEY = "task.feed.#"
  56. CELERY_AMQP_EXCHANGE_TYPE = "topic"
  57. Now to make a Task run on the ``z`` server you need to set its
  58. ``routing_key`` attribute so it starts with the words ``"task.feed."``:
  59. .. code-block:: python
  60. from feedaggregator.models import Feed
  61. from celery.task import Task
  62. class FeedImportTask(Task):
  63. name = "import_feed"
  64. routing_key = "task.feed.importer"
  65. def run(self, feed_url):
  66. # something importing the feed
  67. Feed.objects.import_feed(feed_url)
  68. You can also override this using the ``routing_key`` argument to
  69. :func:`celery.task.apply_async`:
  70. >>> from celery.task import apply_async
  71. >>> from myapp.tasks import RefreshFeedTask
  72. >>> apply_async(RefreshFeedTask, args=["http://cnn.com/rss"],
  73. ... routing_key="task.feed.importer")