Skip to content

Commit

Permalink
Changes the return value of queue_latency to JSON. (#697)
Browse files Browse the repository at this point in the history
* Changes the return value of queue_latency to JSON.

* Appeases the rubocop.

---------

Co-authored-by: Alex Zotov <[email protected]>
  • Loading branch information
bwatson78 and alexBLR authored Jan 3, 2025
1 parent 0226bf6 commit 9e62a2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

mount Sidekiq::Web => '/sidekiq'
match "queue-latency" => proc {
[200, { "Content-Type" => "text/plain" }, [latency_text]]
[200, { "Content-Type" => "application/json" }, [latency_text]]
}, via: :get
mount Qa::Engine => '/authorities'
mount Hyrax::Engine, at: '/'
Expand All @@ -44,9 +44,13 @@
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

# rubocop:disable Rails/FindEach
def latency_text
Sidekiq::Queue.all.map do |q|
"#{q.name} queue latency in seconds: #{q.latency}"
end.join(', ')
ret_hsh = { queues: [] }
Sidekiq::Queue.all.each do |q|
ret_hsh[:queues] << Hash[q.name, q.latency]
end
ret_hsh.to_json
end
# rubocop:enable Rails/FindEach
end
10 changes: 8 additions & 2 deletions spec/features/viewing_the_queue_latency_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
before { visit '/queue-latency' }

it('successfully loads') { expect(page).to have_http_status(:success) }
it('returns plain text') { expect(page.response_headers['Content-Type']).to eq('text/plain') }
it('returns plain text') { expect(page.response_headers['Content-Type']).to eq('application/json') }
# It seems that Circle CI doesn't inherently spin up a queue.
it('contains the expected verbiage') { expect(page.html).to include('queue latency in seconds:') } unless ENV['CI']
unless ENV['CI']
it('contains the expected JSON') do
parsed_json = JSON.parse(page.body)
expect(parsed_json).to be_present
expect(parsed_json['queues']).to be_present
end
end

it 'calls the Sidekiq queue API' do
allow(::Sidekiq::Queue).to receive(:all).and_call_original
Expand Down

0 comments on commit 9e62a2c

Please sign in to comment.