Commit ba5ae175 authored by nazarf's avatar nazarf

add collectioon status

parent 2b794673
......@@ -95,3 +95,6 @@ body.admin-body
.table-error
background-color: #f5c6cb !important
.table-warning
background-color: #ffc107!important
......@@ -79,7 +79,7 @@ class MinersController < AdminController
end
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|
format.html { redirect_to miners_url, notice: 'Miners was set miss' }
format.json { head :no_content }
......
class Miner < ActiveRecord::Base
STATUSES = %w(miss work restart)
end
......@@ -3,7 +3,7 @@
.col-sm-2
= f.input :name
.col-sm-2
= f.input :status
= f.input :status, collection: Miner::STATUSES
.row
.col-sm-2
= f.input :ip_address
......
......@@ -17,8 +17,9 @@
%i.fa.fa-close
%tbody
- @miners.each do |miner|
- failed = miner.status != 'work'
%tr{:class => ("table-error" if failed)}
- miss = miner.status == Miner::STATUSES[0]
- restart = miner.status == Miner::STATUSES[2]
%tr{:class => (miss ? "table-error" : (restart ? "table-warning" : "") )}
%td= link_to miner.name, miner_path(miner)
%td= miner.status
%td= miner.ip_address
......
......@@ -8,12 +8,13 @@ namespace :miners do
miners = Miner.all
if response_json == []
miners.each do |miner|
miner.update(status: 'miss')
end
miners.update_all(status: Miner::STATUSES[0])
end
miners.each do |miner|
if miner.status == Miner::STATUSES[2]
next
end
is_work = false
hr_stats = 0
check_activity_time = (DateTime.now - 5.minutes)
......@@ -28,10 +29,10 @@ namespace :miners do
end
if is_work
miner.update(status: 'work', hash_rate: hr_stats)
miner.update(status: Miner::STATUSES[1], hash_rate: hr_stats)
else
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
......
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