Skip to content

Commit

Permalink
add status controller
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 6, 2018
1 parent 7ed11a5 commit 6ed8dec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/api/status_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Api::StatusController < ApplicationController
def index
process = system("ruby #{Rails.root.join('lib', 'sync_control.rb')} status")

render json: {
result: {
status: process ? "running" : "not running",
currentBlockNumber: CitaSync::Basic.number_to_hex_str(Block.current_block_number || 0),
currentChainBlockNumber: CitaSync::Api.block_number["result"]
}
}
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
resources :blocks, only: [:index]
resources :transactions, only: [:index]
resources :statistics, only: [:index]
resources :status, only: [:index]
end
end
20 changes: 20 additions & 0 deletions spec/controllers/api/status_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

RSpec.describe Api::StatusController, type: :controller do
let(:result) { Oj.load(response.body).with_indifferent_access[:result] }

before do
create :block_zero
mock_block_number
end

context "index" do
it "with no running" do
post :index

expect(result["status"]).to eq "not running"
expect(result["currentBlockNumber"]).to eq "0x0"
expect(result["currentChainBlockNumber"]).to eq "0x1"
end
end
end

0 comments on commit 6ed8dec

Please sign in to comment.