move code to the right place

remove unused code
expand slack test
fix formatting
This commit is contained in:
Niko Storni 2018-05-16 20:08:52 -04:00
parent 788857d2c3
commit bf7b7c0ca6
No known key found for this signature in database
GPG key ID: F37FE63398800368
3 changed files with 21 additions and 23 deletions

View file

@ -6,9 +6,10 @@ import (
"io/ioutil"
"net/http"
"os"
"os/user"
"strings"
"os/user"
"github.com/lbryio/lbry.go/errors"
"github.com/lbryio/lbry.go/null"
"github.com/lbryio/lbry.go/util"
@ -105,6 +106,12 @@ func setChannelSyncStatus(authToken string, channelID string, status string) err
}
func selfSync(cmd *cobra.Command, args []string) {
slackToken := os.Getenv("SLACK_TOKEN")
if slackToken == "" {
log.Error("A slack token was not present in env vars! Slack messages disabled!")
} else {
util.InitSlack(os.Getenv("SLACK_TOKEN"))
}
usr, err := user.Current()
if err != nil {
util.SendToSlackError(err.Error())
@ -116,16 +123,10 @@ func selfSync(cmd *cobra.Command, args []string) {
return
}
if usedPctile > 0.9 && !skipSpaceCheck {
util.SendToSlackError("more than 90% of the space has been used. use --skip-space-check to ignore. %.1f", usedPctile*100)
util.SendToSlackError("more than 90%% of the space has been used. use --skip-space-check to ignore. Used: %.1f%%", usedPctile*100)
return
}
util.SendToSlackInfo("disk usage: %.1f", usedPctile*100)
slackToken := os.Getenv("SLACK_TOKEN")
if slackToken == "" {
log.Error("A slack token was not present in env vars! Slack messages disabled!")
} else {
util.InitSlack(os.Getenv("SLACK_TOKEN"))
}
util.SendToSlackInfo("disk usage: %.1f%%", usedPctile*100)
ytAPIKey := args[0]
authToken := args[1]
@ -216,11 +217,6 @@ func selfSync(cmd *cobra.Command, args []string) {
//this error is very bad. it requires manual intervention
break
}
if limit != 0 && loops >= limit {
util.SendToSlackInfo("limit of %d reached! Stopping", limit)
break
}
}
util.SendToSlackInfo("Syncing process terminated!")
}

View file

@ -27,6 +27,12 @@ func init() {
}
func ytsync(cmd *cobra.Command, args []string) {
slackToken := os.Getenv("SLACK_TOKEN")
if slackToken == "" {
log.Error("A slack token was not present in env vars! Slack messages disabled!")
} else {
util.InitSlack(os.Getenv("SLACK_TOKEN"))
}
usr, err := user.Current()
if err != nil {
util.SendToSlackError(err.Error())
@ -38,16 +44,11 @@ func ytsync(cmd *cobra.Command, args []string) {
return
}
if usedPctile > 0.9 && !skipSpaceCheck {
util.SendToSlackError("more than 90% of the space has been used. use --skip-space-check to ignore. %.1f", usedPctile*100)
util.SendToSlackError("more than 90%% of the space has been used. use --skip-space-check to ignore. Used: %.1f%%", usedPctile*100)
return
}
util.SendToSlackInfo("disk usage: %.1f", usedPctile*100)
slackToken := os.Getenv("SLACK_TOKEN")
if slackToken == "" {
log.Error("A slack token was not present in env vars! Slack messages disabled!")
} else {
util.InitSlack(os.Getenv("SLACK_TOKEN"))
}
util.SendToSlackInfo("disk usage: %.1f%%", usedPctile*100)
ytAPIKey := args[0]
lbryChannelName := args[1]
if string(lbryChannelName[0]) != "@" {

View file

@ -11,5 +11,6 @@ func TestSendToSlack(t *testing.T) {
t.Error("A slack token was not provided")
}
InitSlack(slackToken)
SendToSlackInfo("This is a test :)")
SendToSlackInfo("This is a test :) Working %.2f%%", 1.01*100)
SendToSlackError("This is a test :) Working %.2f%%", 0.01*100)
}