Add transfer of channel after all video's have been transferred

Add channel status call to notify external db that the channel has been transferred.
This commit is contained in:
Mark Beamer Jr 2019-08-20 23:38:36 -04:00 committed by Niko Storni
parent 45cea808ed
commit eb2f6273e4
3 changed files with 40 additions and 4 deletions

View file

@ -100,6 +100,13 @@ const (
VideoStatusTranferFailed = "transferfailed" VideoStatusTranferFailed = "transferfailed"
) )
const (
TransferStateNotTouched = iota
TransferStatePending
TransferStateComplete
TransferStateFailed = -1
)
func (s *SyncManager) Start() error { func (s *SyncManager) Start() error {
if logUtils.ShouldCleanOnStartup() { if logUtils.ShouldCleanOnStartup() {

View file

@ -8,7 +8,7 @@ import (
) )
func TransferChannel(channel *Sync) error { func TransferChannel(channel *Sync) error {
//Transfer channel transferStatus := TransferStateComplete
for _, video := range channel.syncedVideos { for _, video := range channel.syncedVideos {
//Todo - Wait for prior sync to see that the publish is confirmed in lbrycrd? //Todo - Wait for prior sync to see that the publish is confirmed in lbrycrd?
c, err := channel.daemon.ClaimSearch(nil, &video.ClaimID, nil, nil) c, err := channel.daemon.ClaimSearch(nil, &video.ClaimID, nil, nil)
@ -39,6 +39,7 @@ func TransferChannel(channel *Sync) error {
_, err = channel.daemon.StreamUpdate(video.ClaimID, streamUpdateOptions) _, err = channel.daemon.StreamUpdate(video.ClaimID, streamUpdateOptions)
if err != nil { if err != nil {
transferStatus = TransferStateFailed
videoStatus.FailureReason = err.Error() videoStatus.FailureReason = err.Error()
videoStatus.Status = VideoStatusTranferFailed videoStatus.Status = VideoStatusTranferFailed
videoStatus.IsTransferred = util.PtrToBool(false) videoStatus.IsTransferred = util.PtrToBool(false)
@ -51,8 +52,35 @@ func TransferChannel(channel *Sync) error {
return errors.Err(err) return errors.Err(err)
} }
} }
// Todo - Transfer Channel as last step and post back to remote db that channel is transferred. // Todo - Transfer Channel as last step and post back to remote db that channel is transferred.
//Transfer channel
if transferStatus < 0 {
return errors.Err("A video has failed to transfer for the channel...skipping channel transfer")
}
failureReason := ""
channelClaim, err := channel.daemon.ClaimSearch(nil, &channel.lbryChannelID, nil, nil)
if err != nil {
return errors.Err(err)
}
if channelClaim == nil {
return errors.Err("There is no channel claim for channel %s", channel.LbryChannelName)
}
updateOptions := jsonrpc.ChannelUpdateOptions{
ChannelCreateOptions: jsonrpc.ChannelCreateOptions{
ClaimCreateOptions: jsonrpc.ClaimCreateOptions{
ClaimAddress: &channel.publishAddress,
},
},
}
_, err = channel.daemon.ChannelUpdate(channel.lbryChannelID, updateOptions)
if err != nil {
transferStatus = TransferStateFailed
failureReason = err.Error()
}
return nil _, _, channelStatusErr := channel.APIConfig.SetChannelStatus(channel.lbryChannelID, VideoStatusPublished, failureReason, transferStatus)
if channelStatusErr != nil {
return errors.Err(err)
}
return errors.Err(err)
} }

View file

@ -133,7 +133,7 @@ func (a *APIConfig) SetChannelCert(certHex string, channelID string) error {
} }
func (a *APIConfig) SetChannelStatus(channelID string, status string, failureReason string) (map[string]SyncedVideo, map[string]bool, error) { func (a *APIConfig) SetChannelStatus(channelID string, status string, failureReason string, transferState int) (map[string]SyncedVideo, map[string]bool, error) {
type apiChannelStatusResponse struct { type apiChannelStatusResponse struct {
Success bool `json:"success"` Success bool `json:"success"`
Error null.String `json:"error"` Error null.String `json:"error"`
@ -148,6 +148,7 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea
"auth_token": {a.ApiToken}, "auth_token": {a.ApiToken},
"sync_status": {status}, "sync_status": {status},
"failure_reason": {failureReason}, "failure_reason": {failureReason},
"transferred": {strconv.Itoa(transferState)},
}) })
defer res.Body.Close() defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body) body, _ := ioutil.ReadAll(res.Body)