# HG changeset patch # User Nattee Niparnan # Date 2015-09-16 06:10:41 # Node ID 4c7c815d4901fb104580fe69288a68a54f764bc3 # Parent 5a51e5c0329721e278484cf5320c3c6850b4d900 add config for heartbeat response update heartbeat view diff --git a/app/controllers/heartbeat_controller.rb b/app/controllers/heartbeat_controller.rb --- a/app/controllers/heartbeat_controller.rb +++ b/app/controllers/heartbeat_controller.rb @@ -20,11 +20,12 @@ # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) #end HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) - render text: "OK" + + render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') end def index - @hb = HeartBeat.includes(:user).order(:user_id).all + @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count end end diff --git a/app/views/heartbeat/index.html.haml b/app/views/heartbeat/index.html.haml --- a/app/views/heartbeat/index.html.haml +++ b/app/views/heartbeat/index.html.haml @@ -12,7 +12,7 @@ %h1 Heart Beat Count = "Last 5 minutes distinct user count = #{@num}" -%h1 Heart Beat List +%h1 Heart Beat from preview 2 hours %table.tablesorter-cafe#my_table %thead @@ -20,11 +20,13 @@ %th Login %th Full name %th IP - %th Last Update + %th Status + %th Update %tbody - @hb.each do |hb| %tr{class: cycle('info-even','info-odd')} %td= link_to hb.user.login, controller: :users, :action => 'profile', :id => hb.user.id %td= hb.user.full_name %td= hb.ip_address + %td= hb.status %td= "#{time_ago_in_words(hb.updated_at)} ago" diff --git a/db/migrate/20150916054105_update_heart_beat.rb b/db/migrate/20150916054105_update_heart_beat.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20150916054105_update_heart_beat.rb @@ -0,0 +1,10 @@ +class UpdateHeartBeat < ActiveRecord::Migration + def up + GraderConfiguration.create key: 'right.heartbeat_response', value_type: 'string', value:'OK', description:'Heart beat response text' + add_index :heart_beats, :updated_at + end + + def down + remove_index :heart_beats, :updated_at + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150914223258) do +ActiveRecord::Schema.define(:version => 20150916054105) do create_table "announcements", :force => true do |t| t.string "author" @@ -87,6 +87,8 @@ t.string "status" end + add_index "heart_beats", ["updated_at"], :name => "index_heart_beats_on_updated_at" + create_table "languages", :force => true do |t| t.string "name", :limit => 10 t.string "pretty_name"