diff --git a/lib/resque/integration/queues_info/config.rb b/lib/resque/integration/queues_info/config.rb index f428821..8b0f953 100644 --- a/lib/resque/integration/queues_info/config.rb +++ b/lib/resque/integration/queues_info/config.rb @@ -14,16 +14,33 @@ def max_age(queue) threshold(queue, 'max_age') end + def warn_age(queue) + threshold(queue, 'warn_age') + end + def max_size(queue) threshold(queue, 'max_size') end + def warn_size(queue) + threshold(queue, 'warn_size') + end + def max_failures_count(queue, period) threshold(queue, "max_failures_count_per_#{period}") end + def warn_failures_count(queue, period) + threshold(queue, "warn_failures_count_per_#{period}") + end + def channel(queue) - channel = @queues[queue].try(:[], 'channel') || @defaults['channel'] + channel = threshold(queue, 'channel') + Array.wrap(channel).join(' ') + end + + def warn_channel(queue) + channel = threshold(queue, 'warn_channel') Array.wrap(channel).join(' ') end @@ -31,11 +48,18 @@ def data @data ||= @queues.map do |queue_name, _queue_params| { '{#QUEUE}' => queue_name, + + '{#CHANNEL}' => channel(queue_name), '{#THRESHOLD_AGE}' => max_age(queue_name), '{#THRESHOLD_SIZE}' => max_size(queue_name), '{#THRESHOLD_FAILURES_PER_5M}' => max_failures_count(queue_name, '5m'), '{#THRESHOLD_FAILURES_PER_1H}' => max_failures_count(queue_name, '1h'), - '{#CHANNEL}' => channel(queue_name) + + '{#WARNING_CHANNEL}' => warn_channel(queue_name), + '{#WARNING_AGE}' => warn_age(queue_name), + '{#WARNING_SIZE}' => warn_size(queue_name), + '{#WARNING_FAILURES_PER_5M}' => warn_failures_count(queue_name, '5m'), + '{#WARNING_FAILURES_PER_1H}' => warn_failures_count(queue_name, '1h') } end end diff --git a/spec/fixtures/resque_queues.yml b/spec/fixtures/resque_queues.yml index 946426a..83572ee 100644 --- a/spec/fixtures/resque_queues.yml +++ b/spec/fixtures/resque_queues.yml @@ -5,6 +5,12 @@ defaults: max_failures_count_per_1h: 60 channel: default + warn_age: 8 + warn_size: 7 + warn_failures_count_per_5m: 3 + warn_failures_count_per_1h: 30 + warn_channel: default_warnings + queues: ? > @@ -12,17 +18,28 @@ queues: third : max_age: 20 + warn_age: 10 + max_size: 100 + warn_size: 50 + max_failures_count_per_5m: 15 + warn_failures_count_per_5m: 7 + max_failures_count_per_1h: 90 + warn_failures_count_per_1h: 45 + channel: first + warn_channel: first_warnings third: max_age: 30 + warn_age: 15 max_failures_count_per_1h: 70 + warn_failures_count_per_1h: 35 second_queue: channel: [first, second] + warn_channel: [first_warnings, second_warnings] without_channel: {} - diff --git a/spec/resque/integration/queues_info_spec.rb b/spec/resque/integration/queues_info_spec.rb index acbad7c..e7aca3f 100644 --- a/spec/resque/integration/queues_info_spec.rb +++ b/spec/resque/integration/queues_info_spec.rb @@ -338,35 +338,63 @@ expect(queue_info.data).to eq [ { '{#QUEUE}' => 'first', + + '{#CHANNEL}' => 'first', '{#THRESHOLD_AGE}' => 20, '{#THRESHOLD_SIZE}' => 100, '{#THRESHOLD_FAILURES_PER_5M}' => 15, '{#THRESHOLD_FAILURES_PER_1H}' => 90, - '{#CHANNEL}' => 'first' + + '{#WARNING_CHANNEL}' => 'first_warnings', + '{#WARNING_AGE}' => 10, + '{#WARNING_SIZE}' => 50, + '{#WARNING_FAILURES_PER_5M}' => 7, + '{#WARNING_FAILURES_PER_1H}' => 45 }, { '{#QUEUE}' => 'third', + + '{#CHANNEL}' => 'first', '{#THRESHOLD_AGE}' => 30, '{#THRESHOLD_SIZE}' => 100, '{#THRESHOLD_FAILURES_PER_5M}' => 15, '{#THRESHOLD_FAILURES_PER_1H}' => 70, - '{#CHANNEL}' => 'first' + + '{#WARNING_CHANNEL}' => 'first_warnings', + '{#WARNING_AGE}' => 15, + '{#WARNING_SIZE}' => 50, + '{#WARNING_FAILURES_PER_5M}' => 7, + '{#WARNING_FAILURES_PER_1H}' => 35 }, { '{#QUEUE}' => 'second_queue', + + '{#CHANNEL}' => 'first second', '{#THRESHOLD_AGE}' => 10, '{#THRESHOLD_SIZE}' => 10, '{#THRESHOLD_FAILURES_PER_5M}' => 5, '{#THRESHOLD_FAILURES_PER_1H}' => 60, - '{#CHANNEL}' => 'first second' + + '{#WARNING_CHANNEL}' => 'first_warnings second_warnings', + '{#WARNING_AGE}' => 8, + '{#WARNING_SIZE}' => 7, + '{#WARNING_FAILURES_PER_5M}' => 3, + '{#WARNING_FAILURES_PER_1H}' => 30 }, { '{#QUEUE}' => 'without_channel', + + '{#CHANNEL}' => 'default', '{#THRESHOLD_AGE}' => 10, '{#THRESHOLD_SIZE}' => 10, '{#THRESHOLD_FAILURES_PER_5M}' => 5, '{#THRESHOLD_FAILURES_PER_1H}' => 60, - '{#CHANNEL}' => 'default' + + '{#WARNING_CHANNEL}' => 'default_warnings', + '{#WARNING_AGE}' => 8, + '{#WARNING_SIZE}' => 7, + '{#WARNING_FAILURES_PER_5M}' => 3, + '{#WARNING_FAILURES_PER_1H}' => 30 } ] end