A throttler implementation for Exq.
- WORK IN PROGRESS. *
If available in Hex, the package can be installed as:
-
Add exq_throttler to your list of dependencies in
mix.exs:def deps do [{:exq_throttler, "~> 0.0.1"}] end
- Add
Exq.Middleware.Throttlerto yourconfig/*.exs:
# in config/dev.exs
config :exq,
# Note here that Exq.Middleware.Job must exist before Exq.Middleware.Throttler since
# Throttler requires information from Job
middleware: [Exq.Middleware.Job, Exq.Middleware.Throttler, <other middlewares>]
- Add configurations for
Exq.Middlware.Throttlerinconfig/*.exs:
# in config/dev.exs
config :exq,
throttler: [
<queue_name>: [
period: 60,
threshold: 3,
delay: 60
]
]
period and threshold in combine determines when it should throttle. Throttler will check the number of jobs in the period, then delay others according to the delay set in the configuration. Note that it's recommended to have delay >= period.