deanpcmad--sidekiq-limit_fetch/README.md

75 lines
1.9 KiB
Markdown
Raw Normal View History

2013-01-11 10:56:41 +00:00
## Description
2013-01-17 15:21:10 +00:00
Sidekiq strategy to restrict number of workers
2013-01-11 10:56:41 +00:00
which are able to run specified queues simultaneously.
2013-01-24 14:07:21 +00:00
[![Build
Status](https://secure.travis-ci.org/brainopia/sidekiq-limit_fetch.png)](http://travis-ci.org/brainopia/sidekiq-limit_fetch)
2013-01-24 13:46:44 +00:00
[![Gem
Version](https://badge.fury.io/rb/sidekiq-limit_fetch.png)](http://badge.fury.io/rb/sidekiq-limit_fetch)
2013-01-24 13:54:26 +00:00
[![Dependency
2013-01-24 14:35:59 +00:00
Status](https://gemnasium.com/brainopia/sidekiq-limit_fetch.png)](https://gemnasium.com/brainopia/sidekiq-limit_fetch)
2013-01-24 14:34:58 +00:00
[![Code
Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/brainopia/sidekiq-limit_fetch)
2013-01-24 13:54:26 +00:00
2013-01-11 10:56:41 +00:00
## Installation
Add this line to your application's Gemfile:
gem 'sidekiq-limit_fetch'
## Usage
Specify limits which you want to place on queues inside sidekiq.yml:
```yaml
:limits:
queue_name1: 5
queue_name2: 10
2013-01-11 10:56:41 +00:00
```
2013-01-17 15:18:56 +00:00
Or set it dynamically in your code:
```ruby
2013-01-24 12:03:28 +00:00
Sidekiq::Queue['queue_name1'].limit = 5
2013-01-17 15:18:56 +00:00
Sidekiq::Queue['queue_name2'].limit = 10
```
In these examples, tasks for the ```queue_name1``` will be run by at most 5
workers at the same time and the ```queue_name2``` will have no more than 10
2013-01-11 11:02:39 +00:00
workers simultaneously.
2013-01-11 13:07:37 +00:00
2013-01-17 15:18:56 +00:00
Ability to set limits dynamically allows you to resize worker
distribution among queues any time you want.
2013-01-17 15:49:45 +00:00
You can also pause your queues temporarely. Upon continuing their limits
will be preserved.
```ruby
Sidekiq::Queue['name'].pause # prevents workers from running tasks from this queue
...
Sidekiq::Queue['name'].continue # allows workers to use the queue with the same limit
```
You can see how many workers currently handling a queue, eg:
```ruby
Sidekiq::Queue['name'].busy # number of busy workers
```
Limits are applied per process. In case you have several worker
processes and want to have global locks between them, you'll need to
2013-01-24 12:03:28 +00:00
enable global mode by setting global option, eg:
```yaml
:global: true
2013-01-24 12:03:28 +00:00
```
2013-01-17 15:18:56 +00:00
2013-01-11 13:07:37 +00:00
Sponsored by [Evil Martians].
[Evil Martians]: http://evilmartians.com/