-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automation support #10
Conversation
@nikooo777 Is this ready for review? |
negative Tom :) it's work in progress |
e4a795c
to
f44442e
Compare
@lyoshenka there is a lot of work in here, It's not yet ready to be merged but if you want you can take a look at it already and let me know what I should change I'm happy with it. There is some code reuse that I'd like to address and logging is inconsistent: some goes to slack and some doesn't. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall these changes look very messy. I know my ytsync code was messy to begin with, so I'm partially to blame as well. but now that we're planning to use the code for a while, we should come up with a coherent structure and move towards cleaner code. i can discuss with you if you want.
cmd/selfsync.go
Outdated
//PoC | ||
func fetchChannels(authToken string, status string) ([]APIYoutubeChannel, error) { | ||
url := "https://api.lbry.io/yt/jobs" | ||
payload := strings.NewReader("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other solution we discussed worked too :)
cmd/selfsync.go
Outdated
|
||
//PoC | ||
func fetchChannels(authToken string, status string) ([]APIYoutubeChannel, error) { | ||
url := "https://api.lbry.io/yt/jobs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't hardcode this url. the API domain and endpoints should be configured somewhere
util/disk_space.go
Outdated
@@ -0,0 +1,18 @@ | |||
package util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please avoid having a util package as much as possible. it becomes a dump for random code. this function is only used in the cmd package, so it can just be declared there
util/slack.go
Outdated
@@ -0,0 +1,49 @@ | |||
package util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is gonna be in beamer's PR, but it should not go into util
either. we should make our own slack
package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util/slack_test.go
Outdated
"testing" | ||
) | ||
|
||
func TestSendToSlack(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't test anything
ytsync/ytsync.go
Outdated
|
||
func (s *Sync) doSync() error { | ||
var err error | ||
|
||
err = s.walletSetup() | ||
if err != nil { | ||
return err | ||
return errors.Err("Initial wallet setup failed! Manual Intervention is required. Reason: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use errors.Prefix
so you don't lose the original trace
util/slack.go
Outdated
if err != nil { | ||
host = "???" | ||
} | ||
_, _, err = slackApi.PostMessage(slackChannel, message, slack.PostMessageParameters{Username: "YTSYNC (" + host + ")"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lbry.go is a general package used in lots of other places. you can't have a general util function called sendToSlack that says YTSYNC in the message. all ytsync-specific stuff should go into the ytsync package
cmd/selfsync_test.go
Outdated
// such field should be reset to null if the test must be run on a different machine (different hostname) | ||
// and obviously the auth token must be appropriate | ||
func TestSetChannelSyncStatus(t *testing.T) { | ||
err := setChannelSyncStatus("620280", "UCNQfQvFMPnInwsU_iGYArJQ", StatusSyncing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you making calls to the live API here? this is a very weak test. and you're including the auth_token in public code that's visible on github?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to make this clear. the first parameter is the auth token, which is just a number as I'm using this "test" locally. The second parameter is a channel ID.
I basically wrote tests to run the portion of code without having to compile and run the whole program, I believe more code should be tested in a better way. I don't think any of the tests here actually test anything.
Also yesh, I'm calling a local API, not the live API, but the right approach would be to mock the API.
cmd/selfsync.go
Outdated
@@ -0,0 +1,234 @@ | |||
package cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the cmd package very small. it should just gather the CLI options and call a function in the ytsync package. lbry.go
is shared across many different projects. keep your changes in ytsync
package as much as possible.
cmd/common.go
Outdated
@@ -0,0 +1,22 @@ | |||
package cmd | |||
|
|||
const defaultMaxTries = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not common to cmd
. this is common to ytsync
. you also don't need a separate common.go
file. just put it in an existing file
bf3adb1
to
03fe5d2
Compare
03fe5d2
to
df554b7
Compare
44c83d4
to
b64b8d5
Compare
865d7b8
to
2134a81
Compare
add failure cases change interrupt behavior for fatal errors bump up timeout to 20 minutes change max file size to 2GB remove unnecessary utxo wait
improve failure handling adjust slack logging increase file size in string increase publish timeout to 40 minutes
b64b8d5
to
4a4008d
Compare
906c909
to
a273b65
Compare
move functions out of utils address review comments revert lockfile changes
a273b65
to
f800e77
Compare
cmd/selfsync.go
Outdated
) | ||
|
||
func init() { | ||
var selfSyncCmd = &cobra.Command{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the switch from ytsync
to selfsync
. This package is called lbry.go
, so its very general. selfsync
is too generic a name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. I had this built when ytsync was still there, that's why it had a different name. I will change it back.
util/slack.go
Outdated
@@ -46,6 +47,26 @@ func SendToSlack(message string) error { | |||
return sendToSlack(defaultChannel, defaultUsername, message) | |||
} | |||
|
|||
// SendErrorToSlack Sends an error message to the default channel and to the process log. | |||
func SendErrorToSlack(format string, a ...interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these functions should not be in slack.go. first of all, they log the error twice, since sendToSlack
already calls log.Debugln. second, all they do is add an emoji. you can put these functions someplace in the ytsync package if they are used a lot there, but they should not be out here.
however, using fmt.Sprintf
is a nice touch. i support adding that to the existing Send functions.
util/slice.go
Outdated
@@ -8,3 +10,13 @@ func InSlice(str string, values []string) bool { | |||
} | |||
return false | |||
} | |||
|
|||
// ContainedInSlice returns true if fullstring is contained within any element of the candidates slice. False otherwise | |||
func ContainedInSlice(fullString string, candidates []string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name is not that clear. if you saw two functions InSlice
and ContainedInSlice
, could you tell what the difference was?
I'd call this something like SubstringInSlice
also please use the same var names as InSlice (str
, values
) for consistency, unless different names would add clarity.
ytsync/manager.go
Outdated
} | ||
|
||
const ( | ||
StatusPending = "pending" // waiting for permission to sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps these constants should be shared with internal-apis? then they're not defined in two places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea! should i put them in a package of their own?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the way they reside in the code will make them available through the ytsync package once this is merged in master. So nothing to change here I believe
ytsync/manager.go
Outdated
if !response.Data.IsNull() && response.Data.String == "ok" { | ||
return nil | ||
} | ||
return errors.Err("invalid API response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe include the erroneous response in the error?
} | ||
defer func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is pretty confusing. id rather put the rest of FullCycle into another function, call that function, then check the error message and run this deferred stuff on it
if err != nil { | ||
msg := fmt.Sprintf("Failed setting failed state for channel %s.", s.LbryChannelName) | ||
err = errors.Prefix(msg, err) | ||
e = errors.Prefix(err.Error(), e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its kinda redundant to have two Prefix-ings. you can just do e = errors.Prefix(msg + ":" + err.Error(), e)
e = err | ||
} | ||
} | ||
}() | ||
|
||
defaultWalletDir := os.Getenv("HOME") + "/.lbryum/wallets/default_wallet" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you now have a SyncManager that gets configured, this stuff should come from the SyncManager. it should not be set here. as before, calling os.Getenv() here is weird. I know my code did this before, but that should be changed now.
@@ -175,13 +209,17 @@ WaitForDaemonStart: | |||
|
|||
return nil | |||
} | |||
func logShutdownError(shutdownErr error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
the other functions you added to util/slack.go should go here as well
if s.StopOnError { | ||
logMsg := fmt.Sprintf("error processing video: " + err.Error()) | ||
log.Errorln(logMsg) | ||
fatalErrors := []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fatalErrorSubstrings
add video marking support
This addresses https://github.com/lbryio/internal-issues/issues/165