sqs.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. .. _broker-sqs:
  2. ==================
  3. Using Amazon SQS
  4. ==================
  5. .. _broker-sqs-installation:
  6. Installation
  7. ============
  8. For the Amazon SQS support you have to install the `boto`_ library:
  9. .. code-block:: bash
  10. $ pip install -U boto
  11. .. _boto:
  12. http://pypi.python.org/pypi/boto
  13. .. _broker-sqs-configuration:
  14. Configuration
  15. =============
  16. You have to specify SQS in the broker URL::
  17. BROKER_URL = 'sqs://ABCDEFGHIJKLMNOPQRST:ZYXK7NiynGlTogH8Nj+P9nlE73sq3@'
  18. where the URL format is::
  19. sqs://aws_access_key_id:aws_secret_access_key@
  20. you must *remember to include the "@" at the end*.
  21. The login credentials can also be set using the environment variables
  22. :envvar:`AWS_ACCESS_KEY_ID` and :envvar:`AWS_SECRET_ACCESS_KEY`,
  23. in that case the broker url may only be ``sqs://``.
  24. Options
  25. =======
  26. Region
  27. ------
  28. The default region is ``us-east-1`` but you can select another region
  29. by configuring the :setting:`BROKER_TRANSPORT_OPTIONS` setting::
  30. BROKER_TRANSPORT_OPTIONS = {'region': 'eu-west-1'}
  31. .. seealso::
  32. An overview of Amazon Web Services regions can be found here:
  33. http://aws.amazon.com/about-aws/globalinfrastructure/
  34. Visibility Timeout
  35. ------------------
  36. The visibility timeout defines the number of seconds to wait
  37. for the worker to acknowledge the task before the message is redelivered
  38. to another worker. Also see caveats below.
  39. This option is set via the :setting:`BROKER_TRANSPORT_OPTIONS` setting::
  40. BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600} # 1 hour.
  41. The default visibility timeout is 30 seconds.
  42. Polling Interval
  43. ----------------
  44. The polling interval decides the number of seconds to sleep between
  45. unsuccessful polls. This value can be either an int or a float.
  46. By default the value is 1 second, which means that the worker will
  47. sleep for one second whenever there are no more messages to read.
  48. You should note that **more frequent polling is also more expensive, so increasing
  49. the polling interval can save you money**.
  50. The polling interval can be set via the :setting:`BROKER_TRANSPORT_OPTIONS`
  51. setting::
  52. BROKER_TRANSPORT_OPTIONS = {'polling_interval': 0.3}
  53. Very frequent polling intervals can cause *busy loops*, which results in the
  54. worker using a lot of CPU time. If you need sub-millisecond precision you
  55. should consider using another transport, like `RabbitMQ <broker-amqp`,
  56. or `Redis <broker-redis>`.
  57. Queue Prefix
  58. ------------
  59. By default Celery will not assign any prefix to the queue names,
  60. If you have other services using SQS you can configure it do so
  61. using the :setting:`BROKER_TRANSPORT_OPTIONS` setting::
  62. BROKER_TRANSPORT_OPTIONS = {'queue_name_prefix': 'celery-'}
  63. .. _sqs-caveats:
  64. Caveats
  65. =======
  66. - If a task is not acknowledged within the ``visibility_timeout``,
  67. the task will be redelivered to another worker and executed.
  68. This causes problems with ETA/countdown/retry tasks where the
  69. time to execute exceeds the visibility timeout; in fact if that
  70. happens it will be executed again, and again in a loop.
  71. So you have to increase the visibility timeout to match
  72. the time of the longest ETA you are planning to use.
  73. Note that Celery will redeliver messages at worker shutdown,
  74. so having a long visibility timeout will only delay the redelivery
  75. of 'lost' tasks in the event of a power failure or forcefully terminated
  76. workers.
  77. Periodic tasks will not be affected by the visibility timeout,
  78. as it is a concept separate from ETA/countdown.
  79. The maximum visibility timeout supported by AWS as of this writing
  80. is 12 hours (43200 seconds)::
  81. BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 43200}
  82. - SQS does not yet support worker remote control commands.
  83. - SQS does not yet support events, and so cannot be used with
  84. :program:`celery events`, :program:`celerymon` or the Django Admin
  85. monitor.
  86. .. _sqs-results-configuration:
  87. Results
  88. -------
  89. Multiple products in the Amazon Web Services family could be a good candidate
  90. to store or publish results with, but there is no such result backend included
  91. at this point.
  92. .. warning::
  93. Do not use the ``amqp`` backend with SQS.
  94. It will create one queue for every task, and the queues will
  95. not be collected. This could cost you money that would be better
  96. spent contributing an AWS result store backend back to Celery :)