From 459f33bc0662c3e944ffeb4b8537e02c36fa9ef5 Mon Sep 17 00:00:00 2001 From: rolex08 Date: Tue, 14 Feb 2017 18:03:07 +0500 Subject: [PATCH] feature: add channel for each queue for zabbix https://jira.railsc.ru/browse/SG-5633 --- .../resque/queues/status_controller.rb | 2 ++ lib/resque/integration/queues_info.rb | 4 +++ lib/resque/integration/queues_info/config.rb | 4 +++ spec/fixtures/resque_queues.yml | 5 ++++ spec/resque/integration/queues_info_spec.rb | 26 +++++++++++++++++++ 5 files changed, 41 insertions(+) diff --git a/app/controllers/resque/queues/status_controller.rb b/app/controllers/resque/queues/status_controller.rb index a2ccc84..1dc0c60 100644 --- a/app/controllers/resque/queues/status_controller.rb +++ b/app/controllers/resque/queues/status_controller.rb @@ -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 diff --git a/lib/resque/integration/queues_info.rb b/lib/resque/integration/queues_info.rb index af92469..2fc93e3 100644 --- a/lib/resque/integration/queues_info.rb +++ b/lib/resque/integration/queues_info.rb @@ -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 diff --git a/lib/resque/integration/queues_info/config.rb b/lib/resque/integration/queues_info/config.rb index a254d6f..8d0e7ee 100644 --- a/lib/resque/integration/queues_info/config.rb +++ b/lib/resque/integration/queues_info/config.rb @@ -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| { diff --git a/spec/fixtures/resque_queues.yml b/spec/fixtures/resque_queues.yml index dd36b9a..b17e362 100644 --- a/spec/fixtures/resque_queues.yml +++ b/spec/fixtures/resque_queues.yml @@ -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] diff --git a/spec/resque/integration/queues_info_spec.rb b/spec/resque/integration/queues_info_spec.rb index 5419d31..774f64d 100644 --- a/spec/resque/integration/queues_info_spec.rb +++ b/spec/resque/integration/queues_info_spec.rb @@ -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