Commit 54f05aa2 authored by nazarf's avatar nazarf

add monitoring miner on safex pool

parent 7d9678c7
set :output, 'log/cron.log' set :output, 'log/cron.log'
every("*/5 * * * *", roles: [:app]) { rake "miners:check_miners" } # every("*/5 * * * *", roles: [:app]) { rake "miners:check_miners" }
\ No newline at end of file every("*/5 * * * *", roles: [:app]) { rake "miners:check_safex_active_miner" }
\ No newline at end of file
...@@ -38,6 +38,47 @@ namespace :miners do ...@@ -38,6 +38,47 @@ namespace :miners do
end end
end end
task check_safex_active_miner: :environment do
url = 'http://pools.simbowear.com:8117/stats_address?address=Safex5ztaoiBsGxatonmfJfVvEufBEDrRNY4Ha2zTJrf8HSHrB8atKB55VPBAkwmrK6UQZsCNJmLLXKtumBPEEHw5FDrEYzDzWQ4S&longpoll=false'
response = HTTParty.get(url)
response_json = JSON.parse(response.body)
time = DateTime.now
miners = Miner.all
if response_json == []
miners.update_all(status: Miner::STATUSES[0])
end
puts response_json['workers'][0]['name']
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)
last_activity_time = miner.last_activity || check_activity_time
response_json['workers'].each do |item|
if item['name'] == miner.name
is_work = true
hr_stats = item["hashrate"]
puts item["hashrate"]
break
end
end
if is_work
miner.update(status: Miner::STATUSES[1], hash_rate: hr_stats)
else
if last_activity_time <= check_activity_time
miner.update(status: Miner::STATUSES[0], last_activity: time, hash_rate: hr_stats)
end
end
end
end
task get_miners_data: :environment do task get_miners_data: :environment do
session = GoogleDrive::Session.from_service_account_key("client_secret.json") session = GoogleDrive::Session.from_service_account_key("client_secret.json")
spreadsheet ||= session.spreadsheet_by_title("bsa_miners") spreadsheet ||= session.spreadsheet_by_title("bsa_miners")
......
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