Commit 3176e044 authored by nazarf's avatar nazarf

add miner check script

parent 10e56e77
...@@ -15,3 +15,5 @@ ...@@ -15,3 +15,5 @@
/log/* /log/*
!/log/.keep !/log/.keep
/tmp /tmp
/.idea/
...@@ -29,6 +29,8 @@ gem 'bootstrap-will_paginate' ...@@ -29,6 +29,8 @@ gem 'bootstrap-will_paginate'
gem 'momentjs-rails', '>= 2.9.0' gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.15.35' gem 'bootstrap3-datetimepicker-rails', '~> 4.15.35'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "httparty"
gem 'whenever', require: false
group :development do group :development do
gem 'web-console', '~> 2.0' gem 'web-console', '~> 2.0'
......
...@@ -75,6 +75,7 @@ GEM ...@@ -75,6 +75,7 @@ GEM
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
mime-types (>= 1.16) mime-types (>= 1.16)
ssrf_filter (~> 1.0, < 1.1.0) ssrf_filter (~> 1.0, < 1.1.0)
chronic (0.10.2)
ckeditor (5.1.1) ckeditor (5.1.1)
orm_adapter (~> 0.5.0) orm_adapter (~> 0.5.0)
coffee-rails (4.1.1) coffee-rails (4.1.1)
...@@ -118,6 +119,9 @@ GEM ...@@ -118,6 +119,9 @@ GEM
haml (>= 4.0) haml (>= 4.0)
nokogiri (>= 1.6.0) nokogiri (>= 1.6.0)
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (0.9.5) i18n (0.9.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
io-wait (0.3.0) io-wait (0.3.0)
...@@ -153,6 +157,7 @@ GEM ...@@ -153,6 +157,7 @@ GEM
minitest (5.15.0) minitest (5.15.0)
momentjs-rails (2.29.4.1) momentjs-rails (2.29.4.1)
railties (>= 3.1) railties (>= 3.1)
multi_xml (0.6.0)
mysql2 (0.4.10) mysql2 (0.4.10)
nested_form (0.3.2) nested_form (0.3.2)
net-imap (0.2.2) net-imap (0.2.2)
...@@ -267,6 +272,8 @@ GEM ...@@ -267,6 +272,8 @@ GEM
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
whenever (1.0.0)
chronic (>= 0.6.3)
will_paginate (3.3.1) will_paginate (3.3.1)
PLATFORMS PLATFORMS
...@@ -289,6 +296,7 @@ DEPENDENCIES ...@@ -289,6 +296,7 @@ DEPENDENCIES
devise-i18n devise-i18n
font-awesome-rails font-awesome-rails
haml-rails haml-rails
httparty
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
jquery-ui-rails jquery-ui-rails
...@@ -305,6 +313,7 @@ DEPENDENCIES ...@@ -305,6 +313,7 @@ DEPENDENCIES
tzinfo-data tzinfo-data
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
whenever
will_paginate will_paginate
BUNDLED WITH BUNDLED WITH
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
<orderEntry type="library" scope="PROVIDED" name="capistrano-rails (v1.6.2, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="capistrano-rails (v1.6.2, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="capistrano-rvm (v0.1.2, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="capistrano-rvm (v0.1.2, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="carrierwave (v1.3.3, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="carrierwave (v1.3.3, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="chronic (v0.10.2, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="ckeditor (v5.1.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="ckeditor (v5.1.1, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="coffee-rails (v4.1.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="coffee-rails (v4.1.1, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="coffee-script (v2.4.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="coffee-script (v2.4.1, RVM: ruby-2.5.1) [gem]" level="application" />
...@@ -66,6 +67,7 @@ ...@@ -66,6 +67,7 @@
<orderEntry type="library" scope="PROVIDED" name="haml (v5.2.2, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="haml (v5.2.2, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="haml-rails (v1.0.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="haml-rails (v1.0.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="html2haml (v2.3.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="html2haml (v2.3.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="httparty (v0.21.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.9.5, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="i18n (v0.9.5, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="io-wait (v0.3.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="io-wait (v0.3.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="jbuilder (v2.9.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="jbuilder (v2.9.1, RVM: ruby-2.5.1) [gem]" level="application" />
...@@ -83,6 +85,7 @@ ...@@ -83,6 +85,7 @@
<orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.6.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.6.1, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="momentjs-rails (v2.29.4.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="momentjs-rails (v2.29.4.1, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="mysql2 (v0.4.10, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="mysql2 (v0.4.10, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="nested_form (v0.3.2, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="nested_form (v0.3.2, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="net-imap (v0.2.2, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="net-imap (v0.2.2, RVM: ruby-2.5.1) [gem]" level="application" />
...@@ -130,6 +133,7 @@ ...@@ -130,6 +133,7 @@
<orderEntry type="library" scope="PROVIDED" name="uglifier (v4.2.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="uglifier (v4.2.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="warden (v1.2.7, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="warden (v1.2.7, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="web-console (v2.3.0, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="web-console (v2.3.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="whenever (v1.0.0, RVM: ruby-2.5.1) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="will_paginate (v3.3.1, RVM: ruby-2.5.1) [gem]" level="application" /> <orderEntry type="library" scope="PROVIDED" name="will_paginate (v3.3.1, RVM: ruby-2.5.1) [gem]" level="application" />
</component> </component>
<component name="RModuleSettingsStorage"> <component name="RModuleSettingsStorage">
...@@ -462,6 +466,11 @@ ...@@ -462,6 +466,11 @@
<RakeTaskImpl description="" fullCommand="environment" id="environment" /> <RakeTaskImpl description="" fullCommand="environment" id="environment" />
<RakeTaskImpl description="" fullCommand="html" id="html" /> <RakeTaskImpl description="" fullCommand="html" id="html" />
<RakeTaskImpl description="" fullCommand="html/created.rid" id="html/created.rid" /> <RakeTaskImpl description="" fullCommand="html/created.rid" id="html/created.rid" />
<RakeTaskImpl id="miners">
<subtasks>
<RakeTaskImpl description="" fullCommand="miners:check_active_list" id="check_active_list" />
</subtasks>
</RakeTaskImpl>
<RakeTaskImpl id="railties"> <RakeTaskImpl id="railties">
<subtasks> <subtasks>
<RakeTaskImpl id="install"> <RakeTaskImpl id="install">
......
set :output, 'log/cron.log'
every("*/5 * * * *", roles: [:app]) { rake "miners:check_miners" }
\ No newline at end of file
namespace :miners do
task check_active_list: :environment do
url = 'http://149.28.218.119:4243/active_list'
response = HTTParty.get(url)
response_json = JSON.parse(response.body)
time = DateTime.new
miners = Miner.all
if response_json == []
miners.each do |miner|
miner.update(status: 'miss')
end
end
miners.each do |miner|
is_work = false
hr_stats = 0
check_activity_time = (DateTime.now - 5.minutes)
response_json.each do |item|
if item['work_id'] == miner.name
is_work = true
hr_stats = item["hr_stats"]
break
end
end
if is_work
miner.update(status: 'work', hash_rate: hr_stats)
else
if miner.last_activity < check_activity_time
miner.update(status: 'miss', last_activity: time, hash_rate: hr_stats)
end
end
end
end
end
\ No newline at end of file
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