mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Report job queue status via API
This commit is contained in:
17
app/controllers/api/statuses_controller.rb
Normal file
17
app/controllers/api/statuses_controller.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
module Api
|
||||
class StatusesController < BaseController
|
||||
respond_to :json
|
||||
|
||||
def job_queue
|
||||
render json: {alive: job_queue_alive?}
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def job_queue_alive?
|
||||
Spree::Config.last_job_queue_heartbeat_at.present? &&
|
||||
Time.parse(Spree::Config.last_job_queue_heartbeat_at) > 6.minutes.ago
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -143,6 +143,10 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get :managed, on: :collection
|
||||
get :accessible, on: :collection
|
||||
end
|
||||
|
||||
resource :status do
|
||||
get :job_queue
|
||||
end
|
||||
end
|
||||
|
||||
namespace :open_food_network do
|
||||
|
||||
30
spec/controllers/api/statuses_controller_spec.rb
Normal file
30
spec/controllers/api/statuses_controller_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Api
|
||||
describe StatusesController do
|
||||
render_views
|
||||
|
||||
describe "job queue status" do
|
||||
it "returns alive when up to date" do
|
||||
Spree::Config.last_job_queue_heartbeat_at = Time.now
|
||||
spree_get :job_queue
|
||||
response.should be_success
|
||||
response.body.should == {alive: true}.to_json
|
||||
end
|
||||
|
||||
it "returns dead otherwise" do
|
||||
Spree::Config.last_job_queue_heartbeat_at = 10.minutes.ago
|
||||
spree_get :job_queue
|
||||
response.should be_success
|
||||
response.body.should == {alive: false}.to_json
|
||||
end
|
||||
|
||||
it "returns dead when no heartbeat recorded" do
|
||||
Spree::Config.last_job_queue_heartbeat_at = nil
|
||||
spree_get :job_queue
|
||||
response.should be_success
|
||||
response.body.should == {alive: false}.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user