Skip to content
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

Merged
merged 31 commits into from
Jul 25, 2018
Merged

Automation support #10

merged 31 commits into from
Jul 25, 2018

Conversation

nikooo777
Copy link
Collaborator

@nikooo777 nikooo777 added this to the May 9 (web) milestone Apr 30, 2018
@tzarebczan
Copy link
Contributor

@nikooo777 Is this ready for review?

@nikooo777
Copy link
Collaborator Author

negative Tom :) it's work in progress

@nikooo777 nikooo777 force-pushed the automation-support branch from e4a795c to f44442e Compare May 16, 2018 23:42
@nikooo777 nikooo777 requested a review from lyoshenka May 17, 2018 22:46
@lbry-bot lbry-bot assigned lyoshenka and unassigned nikooo777 May 17, 2018
@nikooo777
Copy link
Collaborator Author

@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.

Copy link
Member

@lyoshenka lyoshenka left a 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" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Collaborator Author

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"
Copy link
Member

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

@@ -0,0 +1,18 @@
package util
Copy link
Member

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
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#22

"testing"
)

func TestSendToSlack(t *testing.T) {
Copy link
Member

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)
Copy link
Member

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 + ")"})
Copy link
Member

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

// 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)
Copy link
Member

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?

Copy link
Collaborator Author

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
Copy link
Member

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
Copy link
Member

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

@lbry-bot lbry-bot assigned nikooo777 and unassigned lyoshenka and nikooo777 May 23, 2018
@kauffj kauffj modified the milestones: May 9 (web), May 30 (web) May 23, 2018
@lbry-bot lbry-bot assigned nikooo777 and unassigned nikooo777 May 25, 2018
@nikooo777 nikooo777 force-pushed the automation-support branch from bf3adb1 to 03fe5d2 Compare May 26, 2018 00:50
@lbry-bot lbry-bot assigned nikooo777 and unassigned nikooo777 May 29, 2018
@nikooo777 nikooo777 force-pushed the automation-support branch from 03fe5d2 to df554b7 Compare June 4, 2018 14:36
@nikooo777 nikooo777 force-pushed the automation-support branch from 44c83d4 to b64b8d5 Compare June 17, 2018 23:51
@lyoshenka lyoshenka force-pushed the master branch 3 times, most recently from 865d7b8 to 2134a81 Compare June 27, 2018 20:27
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
@nikooo777 nikooo777 force-pushed the automation-support branch from b64b8d5 to 4a4008d Compare July 12, 2018 13:04
merge sync and selfsync
export sync manager out of cmd package
clean up ytsync.go
address #19 and #20
move functions out of utils
address review comments
revert lockfile changes
@nikooo777 nikooo777 force-pushed the automation-support branch from a273b65 to f800e77 Compare July 18, 2018 12:47
cmd/selfsync.go Outdated
)

func init() {
var selfSyncCmd = &cobra.Command{
Copy link
Member

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.

Copy link
Collaborator Author

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 {
Copy link
Member

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 {
Copy link
Member

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.

}

const (
StatusPending = "pending" // waiting for permission to sync
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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

if !response.Data.IsNull() && response.Data.String == "ok" {
return nil
}
return errors.Err("invalid API response")
Copy link
Member

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() {
Copy link
Member

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)
Copy link
Member

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"
Copy link
Member

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) {
Copy link
Member

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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fatalErrorSubstrings

@lbry-bot lbry-bot assigned nikooo777 and unassigned lyoshenka and nikooo777 Jul 19, 2018
@lyoshenka lyoshenka merged commit 7322d40 into master Jul 25, 2018
@lyoshenka lyoshenka deleted the automation-support branch July 25, 2018 14:38
@nikooo777 nikooo777 mentioned this pull request Aug 2, 2018
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants