faq.txt 3.1 KB

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