Archived
1
0
Fork 0

feat: Add offline/online workers notifications (#1)

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-10-10 20:56:11 +02:00
commit c4f3854861
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
8 changed files with 175 additions and 6 deletions

View file

@ -15,6 +15,7 @@ type Notifier interface {
NotifyBalance(miner Miner, difference float64) error
NotifyPayment(miner Miner, payment Payment) error
NotifyBlock(pool Pool, block Block) error
NotifyOfflineWorker(worker Worker) error
}
// TelegramNotifier to send notifications using Telegram
@ -121,3 +122,15 @@ func (t *TelegramNotifier) NotifyBlock(pool Pool, block Block) error {
message := fmt.Sprintf("🎉 *%s* [#%.0f](%s) _%s_", verb, block.Number, url, ac.FormatMoney(convertedValue))
return t.sendMessage(message)
}
// NotifyOfflineWorker sends a message when a worker is online or offline
func (t *TelegramNotifier) NotifyOfflineWorker(worker Worker) error {
stateIcon := "🟢"
stateMessage := "online"
if !worker.IsOnline {
stateIcon = "🔴"
stateMessage = "offline"
}
message := fmt.Sprintf("%s *Worker* _%s_ is %s", stateIcon, worker.Name, stateMessage)
return t.sendMessage(message)
}