use retry from post

This commit is contained in:
Celogeek 2023-01-08 16:32:26 +01:00
parent b98102a596
commit 48c383d8b2
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 15 additions and 17 deletions

View File

@ -26,12 +26,12 @@ func (c *ImagesUploadTreeCommand) Execute(args []string) error {
stat := piwigotools.NewFileToUploadStat()
defer stat.Close()
filesToCheck := make(chan *piwigotools.FileToUpload, 1000)
files := make(chan *piwigotools.FileToUpload, 1000)
filesToCheck := make(chan *piwigotools.FileToUpload, 10000)
files := make(chan *piwigotools.FileToUpload, 10000)
go p.ScanTree(c.Dirname, c.CategoryId, 0, &status.UploadFileType, stat, filesToCheck)
go p.CheckFiles(filesToCheck, files, stat, 8)
p.UploadFiles(files, stat, hasVideoJS, 4, 2)
p.UploadFiles(files, stat, hasVideoJS, c.NbJobs, 2)
return nil
}

View File

@ -92,16 +92,13 @@ func (p *Piwigo) Upload(file *piwigotools.FileToUpload, stat *piwigotools.FileTo
p.mu.Lock()
defer p.mu.Unlock()
for i := 0; i < 3; i++ {
err = p.Post("pwg.images.add", data, &resp)
if err == nil || err.Error() == "[Error 500] file already exists" {
err = nil
break
}
stat.Error(fmt.Sprintf("Upload %d", i), *file.FullPath(), err)
err = p.Post("pwg.images.add", data, &resp)
if err == nil || err.Error() == "[Error 500] file already exists" {
err = nil
}
if err != nil {
stat.Error("Upload", *file.FullPath(), err)
stat.Fail()
return
}
@ -126,15 +123,12 @@ func (p *Piwigo) UploadChunk(file *piwigotools.FileToUpload, chunks chan *piwigo
"type": []string{"file"},
"data": []string{chunk.Buffer.String()},
}
for i := 0; i < 3; i++ {
err = p.Post("pwg.images.addChunk", data, nil)
if err == nil {
break
}
stat.Error(fmt.Sprintf("UploadChunk %d", i), *file.FullPath(), err)
}
err = p.Post("pwg.images.addChunk", data, nil)
stat.Commit(chunk.Size)
if err != nil {
stat.Error("UploadChunk", *file.FullPath(), err)
stat.Fail()
*ok = false
return

View File

@ -9,6 +9,7 @@ import (
"net/url"
"os"
"strings"
"time"
"github.com/celogeek/piwigo-cli/internal/debug"
)
@ -52,6 +53,9 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
raw := bytes.NewBuffer([]byte{})
for i := 0; i < 3; i++ {
if i > 0 {
time.Sleep(time.Second) // wait 1 sec before retry
}
req, err := http.NewRequest("POST", Url, strings.NewReader(encodedForm))
if err != nil {
return err