Description:
add config for heartbeat response update heartbeat view
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r538:4c7c815d4901 - - 4 files changed: 20 inserted, 5 deleted

@@ -0,0 +1,10
1 + class UpdateHeartBeat < ActiveRecord::Migration
2 + def up
3 + GraderConfiguration.create key: 'right.heartbeat_response', value_type: 'string', value:'OK', description:'Heart beat response text'
4 + add_index :heart_beats, :updated_at
5 + end
6 +
7 + def down
8 + remove_index :heart_beats, :updated_at
9 + end
10 + end
@@ -1,30 +1,31
1 class HeartbeatController < ApplicationController
1 class HeartbeatController < ApplicationController
2 before_filter :admin_authorization, :only => ['index']
2 before_filter :admin_authorization, :only => ['index']
3
3
4 def edit
4 def edit
5 @user = User.find_by_login(params[:id])
5 @user = User.find_by_login(params[:id])
6 unless @user
6 unless @user
7 render text: "LOGIN_NOT_FOUND"
7 render text: "LOGIN_NOT_FOUND"
8 return
8 return
9 end
9 end
10
10
11 #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
11 #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
12 #puts "status = #{params[:status]}"
12 #puts "status = #{params[:status]}"
13 #if hb
13 #if hb
14 # if params[:status]
14 # if params[:status]
15 # hb.status = params[:status]
15 # hb.status = params[:status]
16 # hb.save
16 # hb.save
17 # end
17 # end
18 # hb.touch
18 # hb.touch
19 #else
19 #else
20 # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
20 # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
21 #end
21 #end
22 HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status])
22 HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status])
23 - render text: "OK"
23 +
24 + render text: (GraderConfiguration['right.heartbeat_response'] || 'OK')
24 end
25 end
25
26
26 def index
27 def index
27 - @hb = HeartBeat.includes(:user).order(:user_id).all
28 + @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all
28 @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count
29 @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count
29 end
30 end
30 end
31 end
@@ -1,30 +1,32
1 - content_for :header do
1 - content_for :header do
2 = javascript_include_tag 'local_jquery'
2 = javascript_include_tag 'local_jquery'
3 = stylesheet_link_tag 'tablesorter-theme.cafe'
3 = stylesheet_link_tag 'tablesorter-theme.cafe'
4
4
5 %script{:type=>"text/javascript"}
5 %script{:type=>"text/javascript"}
6 $(function () {
6 $(function () {
7 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
7 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
9 $('#my_table').tablesorter({widgets: ['zebra']});
9 $('#my_table').tablesorter({widgets: ['zebra']});
10 });
10 });
11
11
12 %h1 Heart Beat Count
12 %h1 Heart Beat Count
13 = "Last 5 minutes distinct user count = #{@num}"
13 = "Last 5 minutes distinct user count = #{@num}"
14
14
15 - %h1 Heart Beat List
15 + %h1 Heart Beat from preview 2 hours
16
16
17 %table.tablesorter-cafe#my_table
17 %table.tablesorter-cafe#my_table
18 %thead
18 %thead
19 %tr
19 %tr
20 %th Login
20 %th Login
21 %th Full name
21 %th Full name
22 %th IP
22 %th IP
23 - %th Last Update
23 + %th Status
24 + %th Update
24 %tbody
25 %tbody
25 - @hb.each do |hb|
26 - @hb.each do |hb|
26 %tr{class: cycle('info-even','info-odd')}
27 %tr{class: cycle('info-even','info-odd')}
27 %td= link_to hb.user.login, controller: :users, :action => 'profile', :id => hb.user.id
28 %td= link_to hb.user.login, controller: :users, :action => 'profile', :id => hb.user.id
28 %td= hb.user.full_name
29 %td= hb.user.full_name
29 %td= hb.ip_address
30 %td= hb.ip_address
31 + %td= hb.status
30 %td= "#{time_ago_in_words(hb.updated_at)} ago"
32 %td= "#{time_ago_in_words(hb.updated_at)} ago"
@@ -1,38 +1,38
1 # encoding: UTF-8
1 # encoding: UTF-8
2 # This file is auto-generated from the current state of the database. Instead
2 # This file is auto-generated from the current state of the database. Instead
3 # of editing this file, please use the migrations feature of Active Record to
3 # of editing this file, please use the migrations feature of Active Record to
4 # incrementally modify your database, and then regenerate this schema definition.
4 # incrementally modify your database, and then regenerate this schema definition.
5 #
5 #
6 # Note that this schema.rb definition is the authoritative source for your
6 # Note that this schema.rb definition is the authoritative source for your
7 # database schema. If you need to create the application database on another
7 # database schema. If you need to create the application database on another
8 # system, you should be using db:schema:load, not running all the migrations
8 # system, you should be using db:schema:load, not running all the migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 #
11 #
12 # It's strongly recommended to check this file into your version control system.
12 # It's strongly recommended to check this file into your version control system.
13
13
14 - ActiveRecord::Schema.define(:version => 20150914223258) do
14 + ActiveRecord::Schema.define(:version => 20150916054105) do
15
15
16 create_table "announcements", :force => true do |t|
16 create_table "announcements", :force => true do |t|
17 t.string "author"
17 t.string "author"
18 t.text "body"
18 t.text "body"
19 t.boolean "published"
19 t.boolean "published"
20 t.datetime "created_at", :null => false
20 t.datetime "created_at", :null => false
21 t.datetime "updated_at", :null => false
21 t.datetime "updated_at", :null => false
22 t.boolean "frontpage", :default => false
22 t.boolean "frontpage", :default => false
23 t.boolean "contest_only", :default => false
23 t.boolean "contest_only", :default => false
24 t.string "title"
24 t.string "title"
25 t.string "notes"
25 t.string "notes"
26 end
26 end
27
27
28 create_table "contests", :force => true do |t|
28 create_table "contests", :force => true do |t|
29 t.string "title"
29 t.string "title"
30 t.boolean "enabled"
30 t.boolean "enabled"
31 t.datetime "created_at", :null => false
31 t.datetime "created_at", :null => false
32 t.datetime "updated_at", :null => false
32 t.datetime "updated_at", :null => false
33 t.string "name"
33 t.string "name"
34 end
34 end
35
35
36 create_table "contests_problems", :id => false, :force => true do |t|
36 create_table "contests_problems", :id => false, :force => true do |t|
37 t.integer "contest_id"
37 t.integer "contest_id"
38 t.integer "problem_id"
38 t.integer "problem_id"
@@ -66,48 +66,50
66 end
66 end
67
67
68 create_table "grader_processes", :force => true do |t|
68 create_table "grader_processes", :force => true do |t|
69 t.string "host", :limit => 20
69 t.string "host", :limit => 20
70 t.integer "pid"
70 t.integer "pid"
71 t.string "mode"
71 t.string "mode"
72 t.boolean "active"
72 t.boolean "active"
73 t.datetime "created_at", :null => false
73 t.datetime "created_at", :null => false
74 t.datetime "updated_at", :null => false
74 t.datetime "updated_at", :null => false
75 t.integer "task_id"
75 t.integer "task_id"
76 t.string "task_type"
76 t.string "task_type"
77 t.boolean "terminated"
77 t.boolean "terminated"
78 end
78 end
79
79
80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
81
81
82 create_table "heart_beats", :force => true do |t|
82 create_table "heart_beats", :force => true do |t|
83 t.integer "user_id"
83 t.integer "user_id"
84 t.string "ip_address"
84 t.string "ip_address"
85 t.datetime "created_at", :null => false
85 t.datetime "created_at", :null => false
86 t.datetime "updated_at", :null => false
86 t.datetime "updated_at", :null => false
87 t.string "status"
87 t.string "status"
88 end
88 end
89
89
90 + add_index "heart_beats", ["updated_at"], :name => "index_heart_beats_on_updated_at"
91 +
90 create_table "languages", :force => true do |t|
92 create_table "languages", :force => true do |t|
91 t.string "name", :limit => 10
93 t.string "name", :limit => 10
92 t.string "pretty_name"
94 t.string "pretty_name"
93 t.string "ext", :limit => 10
95 t.string "ext", :limit => 10
94 t.string "common_ext"
96 t.string "common_ext"
95 end
97 end
96
98
97 create_table "logins", :force => true do |t|
99 create_table "logins", :force => true do |t|
98 t.integer "user_id"
100 t.integer "user_id"
99 t.string "ip_address"
101 t.string "ip_address"
100 t.datetime "created_at", :null => false
102 t.datetime "created_at", :null => false
101 t.datetime "updated_at", :null => false
103 t.datetime "updated_at", :null => false
102 end
104 end
103
105
104 create_table "messages", :force => true do |t|
106 create_table "messages", :force => true do |t|
105 t.integer "sender_id"
107 t.integer "sender_id"
106 t.integer "receiver_id"
108 t.integer "receiver_id"
107 t.integer "replying_message_id"
109 t.integer "replying_message_id"
108 t.text "body"
110 t.text "body"
109 t.boolean "replied"
111 t.boolean "replied"
110 t.datetime "created_at", :null => false
112 t.datetime "created_at", :null => false
111 t.datetime "updated_at", :null => false
113 t.datetime "updated_at", :null => false
112 end
114 end
113
115
You need to be logged in to leave comments. Login now