# Sidekiq limit_fetch

> Sidekiq strategy to support a granular queue control—limiting, pausing, blocking, querying.

- URL: https://evilmartians.com/opensource/sidekiq-limit-fetch
- GitHub: https://github.com/brainopia/sidekiq-limit_fetch
- Authors: Ravil Bayramgalin

---

Sidekiq strategy to support a granular queue control—limiting, pausing, blocking, querying.

### Usage

If you are using this with Rails, you don't need to require it as it's done automatically.

To use this Gem in other Ruby projects, just add `require 'sidekiq-limit_fetch'`.

### Limits

Specify limits which you want to place on queues inside sidekiq.yml:

```yaml
:limits:
  queue_name1: 5
  queue_name2: 10
```

Or set it dynamically in your code:
```ruby
Sidekiq::Queue['queue_name1'].limit = 5
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 workers simultaneously.

Ability to set limits dynamically allows you to resize worker distribution among queues any time you want.

### Limits per process

If you use multiple sidekiq processes then you can specify limits per process:

```yaml
:process_limits:
  queue_name: 2
```

Or set it in your code:

```ruby
Sidekiq::Queue['queue_name'].process_limit = 2
```

### Busy workers by queue

You can see how many workers currently handling a queue:

```ruby
Sidekiq::Queue['name'].busy # number of busy workers
```

### Pauses

You can also pause your queues temporarily. Upon continuing their limits
will be preserved.

```ruby
Sidekiq::Queue['name'].pause # prevents workers from running tasks from this queue
Sidekiq::Queue['name'].paused? # => true
Sidekiq::Queue['name'].unpause # allows workers to use the queue
Sidekiq::Queue['name'].pause_for_ms(1000) # will pause for a second
```
