Skip to content

Commit

Permalink
feature: add channel for each queue for zabbix
Browse files Browse the repository at this point in the history
  • Loading branch information
rolex08 committed Feb 16, 2017
1 parent 9518bfc commit 459f33b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/resque/queues/status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def show
Resque.queues_info.threshold_size(params.fetch('queue'))
when 'threshold_age'
Resque.queues_info.threshold_age(params.fetch('queue'))
when 'channel'
Resque.queues_info.channel(params.fetch('queue'))
else
0
end.to_s
Expand Down
4 changes: 4 additions & 0 deletions lib/resque/integration/queues_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def threshold_age(queue)
@config.max_age(queue)
end

def channel(queue)
@config.channel(queue)
end

def data
@config.data
end
Expand Down
4 changes: 4 additions & 0 deletions lib/resque/integration/queues_info/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def max_size(queue)
threshold(queue, 'max_size')
end

def channel(queue)
Array.wrap((@queues[queue] || @defaults)['channel']).join(' ')
end

def data
@data ||= @queues.map do |k, v|
{
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/resque_queues.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
defaults:
max_age: 10
max_size: 10
channel: default

queues:
first:
max_age: 20
max_size: 100
channel: first

second_queue:
channel: [first, second]
26 changes: 26 additions & 0 deletions spec/resque/integration/queues_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,30 @@
end
end
end

describe '#channel' do
context 'when queue defined in config' do
context 'when returns the one channel' do
let(:queue_name) { 'first' }

it { expect(queue_info.channel(queue_name)).to eq 'first' }
end

context 'when returns several channels' do
let(:queue_name) { 'second_queue' }

it do
expect(queue_info.channel(queue_name)).to eq 'first second'
end
end
end

context 'when queue not defined in config' do
let(:queue_name) { 'other_queue' }

it 'returns channel' do
expect(queue_info.channel(queue_name)).to eq 'default'
end
end
end
end

0 comments on commit 459f33b

Please sign in to comment.