Commit 0a5d8d83 authored by nazarf's avatar nazarf

Fix send notification

parent 1908a7ed
namespace :miners do namespace :miners do
task miners_status_notification: :environment do
require 'logger'
require 'telegram_bot'
TELEGRAM_BOT_TOKEN = "5829604433:AAG5CeFBygU1lvV5oeeDyT_v0CqzjAWCNlY"
CHAT_ID = "-1001516309000"
bot = TelegramBot.new(token: TELEGRAM_BOT_TOKEN, logger: Logger.new(STDOUT))
channel = TelegramBot::Channel.new(id: CHAT_ID)
message = TelegramBot::OutMessage.new
message.chat = channel
miss_miner = Miner.where(status: Miner::STATUSES[0])
restart_miner = Miner.where(status: Miner::STATUSES[2])
active_miner = Miner.where(status: Miner::STATUSES[1])
message.text = "Date: #{DateTime.now.strftime("%d.%m.%Y %H:%M")}\n
Total: #{Miner.count}\n
Active: #{active_miner.count}\n
Restart: #{restart_miner.count}\n
#{restart_miner.map(&:name).join(', ')}\n
Miss: #{miss_miner.count}\n
#{miss_miner.map(&:name).join(', ')}
"
message.send_with(bot)
end
task check_active_list: :environment do task check_active_list: :environment do
url = 'http://149.28.218.119:4243/active_list' url = 'http://149.28.218.119:4243/active_list'
response = HTTParty.get(url) response = HTTParty.get(url)
...@@ -134,29 +162,3 @@ namespace :miners do ...@@ -134,29 +162,3 @@ namespace :miners do
end end
end end
end end
\ No newline at end of file
task miners_status_notification: :environment do
require 'logger'
require 'telegram_bot'
TELEGRAM_BOT_TOKEN = "5829604433:AAG5CeFBygU1lvV5oeeDyT_v0CqzjAWCNlY"
CHAT_ID = "-1001516309000"
bot = TelegramBot.new(token: TELEGRAM_BOT_TOKEN, logger: Logger.new(STDOUT))
channel = TelegramBot::Channel.new(id: CHAT_ID)
message = TelegramBot::OutMessage.new
message.chat = channel
miss_miner = Miner.where(status: Miner::STATUSES[0])
restart_miner = Miner.where(status: Miner::STATUSES[1])
active_miner = Miner.where(status: Miner::STATUSES[2])
message.text = "Date: #{DateTime.now.strftime("%d.%m.%Y %H:%M")}\n
Total: #{Miner.count}\n
Active: #{active_miner.count}\n
Restart: #{restart_miner.count}\n
Miss: #{miss_miner.count}\n
#{miss_miner.map(&:name).join(', ')}
"
message.send_with(bot)
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