Commit ba5ae175 authored by nazarf's avatar nazarf

add collectioon status

parent 2b794673
...@@ -95,3 +95,6 @@ body.admin-body ...@@ -95,3 +95,6 @@ body.admin-body
.table-error .table-error
background-color: #f5c6cb !important background-color: #f5c6cb !important
.table-warning
background-color: #ffc107!important
...@@ -79,7 +79,7 @@ class MinersController < AdminController ...@@ -79,7 +79,7 @@ class MinersController < AdminController
end end
def set_miners_miss def set_miners_miss
Miner.update_all(status: 'miss', last_activity: Time.now) Miner.update_all(status: Miner::STATUSES[0], last_activity: Time.now)
respond_to do |format| respond_to do |format|
format.html { redirect_to miners_url, notice: 'Miners was set miss' } format.html { redirect_to miners_url, notice: 'Miners was set miss' }
format.json { head :no_content } format.json { head :no_content }
......
class Miner < ActiveRecord::Base class Miner < ActiveRecord::Base
STATUSES = %w(miss work restart)
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
.col-sm-2 .col-sm-2
= f.input :name = f.input :name
.col-sm-2 .col-sm-2
= f.input :status = f.input :status, collection: Miner::STATUSES
.row .row
.col-sm-2 .col-sm-2
= f.input :ip_address = f.input :ip_address
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
%i.fa.fa-close %i.fa.fa-close
%tbody %tbody
- @miners.each do |miner| - @miners.each do |miner|
- failed = miner.status != 'work' - miss = miner.status == Miner::STATUSES[0]
%tr{:class => ("table-error" if failed)} - restart = miner.status == Miner::STATUSES[2]
%tr{:class => (miss ? "table-error" : (restart ? "table-warning" : "") )}
%td= link_to miner.name, miner_path(miner) %td= link_to miner.name, miner_path(miner)
%td= miner.status %td= miner.status
%td= miner.ip_address %td= miner.ip_address
......
...@@ -8,12 +8,13 @@ namespace :miners do ...@@ -8,12 +8,13 @@ namespace :miners do
miners = Miner.all miners = Miner.all
if response_json == [] if response_json == []
miners.each do |miner| miners.update_all(status: Miner::STATUSES[0])
miner.update(status: 'miss')
end
end end
miners.each do |miner| miners.each do |miner|
if miner.status == Miner::STATUSES[2]
next
end
is_work = false is_work = false
hr_stats = 0 hr_stats = 0
check_activity_time = (DateTime.now - 5.minutes) check_activity_time = (DateTime.now - 5.minutes)
...@@ -28,10 +29,10 @@ namespace :miners do ...@@ -28,10 +29,10 @@ namespace :miners do
end end
if is_work if is_work
miner.update(status: 'work', hash_rate: hr_stats) miner.update(status: Miner::STATUSES[1], hash_rate: hr_stats)
else else
if last_activity_time <= check_activity_time if last_activity_time <= check_activity_time
miner.update(status: 'miss', last_activity: time, hash_rate: hr_stats) miner.update(status: Miner::STATUSES[0], last_activity: time, hash_rate: hr_stats)
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment