queue.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Asynchronous Workers
  2. ====================
  3. Sentry comes with a built-in queue to process tasks in a more asynchronous
  4. fashion. For example when an event comes in instead of writing it to the database
  5. immediately, it sends a job to the queue so that the request can be returned right
  6. away, and the background workers handle actually saving that data.
  7. .. note:: We rely on the `Celery <http://celeryproject.org/>`_ library for managing workers.
  8. Running a Worker
  9. ----------------
  10. Workers can be run by using the Sentry CLI.
  11. .. code-block:: bash
  12. $ sentry run worker
  13. We again recommend running this as a service. Below is an example
  14. configuration with supervisor::
  15. [program:sentry-worker]
  16. directory=/www/sentry/
  17. command=/www/sentry/bin/sentry run worker -l WARNING
  18. autostart=true
  19. autorestart=true
  20. redirect_stderr=true
  21. killasgroup=true
  22. Starting the Cron Process
  23. -------------------------
  24. Sentry also needs a cron process:
  25. ::
  26. SENTRY_CONF=/etc/sentry sentry run cron
  27. We again recommend running this as a service. Below is an example
  28. configuration with supervisor::
  29. [program:sentry-cron]
  30. directory=/www/sentry/
  31. command=/www/sentry/bin/sentry run cron
  32. autostart=true
  33. autorestart=true
  34. redirect_stderr=true
  35. killasgroup=true
  36. It's recommended to only run one of them at the time or you will see
  37. unnecessary extra tasks being pushed onto the queues but the system will
  38. still behave as intended if multiple beat processes are run. This can be
  39. used to achieve high availability.
  40. Configuring the Broker
  41. ----------------------
  42. Sentry supports two primary brokers which may be adjusted depending on your
  43. workload: RabbitMQ and Redis.
  44. Redis
  45. `````
  46. The default broker is Redis, and will work under most situations. The primary
  47. limitation to using Redis is that all pending work must fit in memory.
  48. .. code-block:: python
  49. BROKER_URL = "redis://localhost:6379/0"
  50. If your Redis connection requires a password for authentication, you need to use
  51. the following format:
  52. .. code-block:: python
  53. BROKER_URL = "redis://:password@localhost:6379/0"
  54. RabbitMQ
  55. ````````
  56. If you run with a high workload, or have concerns about fitting the pending workload
  57. in memory, then RabbitMQ is an ideal candidate for backing Sentry's workers.
  58. .. code-block:: python
  59. BROKER_URL = "amqp://guest:guest@localhost:5672/sentry"