fix wallet refill handler

add slack logging
add PoC for channel fetching
This commit is contained in:
Niko Storni 2018-04-26 06:12:54 -04:00
parent 65ed9d7b4b
commit 6e3a34f0e0

View file

@ -22,6 +22,8 @@ import (
"github.com/lbryio/lbry.go/ytsync/redisdb" "github.com/lbryio/lbry.go/ytsync/redisdb"
"github.com/lbryio/lbry.go/ytsync/sources" "github.com/lbryio/lbry.go/ytsync/sources"
"fmt"
"github.com/lbryio/lbry.go/util"
"github.com/mitchellh/go-ps" "github.com/mitchellh/go-ps"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"google.golang.org/api/googleapi/transport" "google.golang.org/api/googleapi/transport"
@ -103,16 +105,14 @@ func (s *Sync) FullCycle() error {
log.Printf("Stopping daemon") log.Printf("Stopping daemon")
shutdownErr := stopDaemonViaSystemd() shutdownErr := stopDaemonViaSystemd()
if shutdownErr != nil { if shutdownErr != nil {
log.Errorf("error shutting down daemon: %v", shutdownErr) logShutdownError(shutdownErr)
log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
} else { } else {
// the cli will return long before the daemon effectively stops. we must observe the processes running // the cli will return long before the daemon effectively stops. we must observe the processes running
// before moving the wallet // before moving the wallet
var waitTimeout time.Duration = 60 * 6 var waitTimeout time.Duration = 60 * 6
processDeathError := waitForDaemonProcess(waitTimeout) processDeathError := waitForDaemonProcess(waitTimeout)
if processDeathError != nil { if processDeathError != nil {
log.Errorf("error shutdown down daemon: %v", processDeathError) logShutdownError(processDeathError)
log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
} else { } else {
walletErr := os.Rename(defaultWalletDir, walletBackupDir) walletErr := os.Rename(defaultWalletDir, walletBackupDir)
if walletErr != nil { if walletErr != nil {
@ -175,6 +175,13 @@ WaitForDaemonStart:
return nil return nil
} }
func logShutdownError(shutdownErr error) {
errMsg := fmt.Sprintf("error shutting down daemon: %v", shutdownErr)
log.Errorf(errMsg)
util.SendToSlack(errMsg)
log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
util.SendToSlack("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
}
func (s *Sync) doSync() error { func (s *Sync) doSync() error {
var err error var err error
@ -235,7 +242,9 @@ func (s *Sync) startWorker(workerNum int) {
err := s.processVideo(v) err := s.processVideo(v)
if err != nil { if err != nil {
log.Errorln("error processing video: " + err.Error()) logMsg := fmt.Sprintf("error processing video: " + err.Error())
log.Errorln(logMsg)
if s.StopOnError { if s.StopOnError {
s.grp.Stop() s.grp.Stop()
} else if s.MaxTries > 1 { } else if s.MaxTries > 1 {
@ -247,9 +256,10 @@ func (s *Sync) startWorker(workerNum int) {
strings.Contains(err.Error(), "Playback on other websites has been disabled by the video owner") { strings.Contains(err.Error(), "Playback on other websites has been disabled by the video owner") {
log.Println("This error should not be retried at all") log.Println("This error should not be retried at all")
} else if tryCount < s.MaxTries { } else if tryCount < s.MaxTries {
if strings.Contains(err.Error(), "The transaction was rejected by network rules.(258: txn-mempool-conflict)") { if strings.Contains(err.Error(), "The transaction was rejected by network rules.(258: txn-mempool-conflict)") ||
strings.Contains(err.Error(), "failed: Not enough funds") {
log.Println("waiting for a block and refilling addresses before retrying") log.Println("waiting for a block and refilling addresses before retrying")
err = s.ensureEnoughUTXOs() err = s.walletSetup()
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
@ -257,7 +267,9 @@ func (s *Sync) startWorker(workerNum int) {
log.Println("Retrying") log.Println("Retrying")
continue continue
} }
log.Printf("Video failed after %d retries, skipping", s.MaxTries) logMsg = fmt.Sprintf("Video failed after %d retries, skipping. Stack: %s", s.MaxTries, logMsg)
log.Printf(logMsg)
util.SendToSlack(logMsg)
} }
} }
break break