8000 v1.6.2 by kbairak · Pull Request #140 · transifex/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

v1.6.2 #140

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

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions internal/txlib/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,7 @@ func (task *FilePullTask) Run(send func(string), abort func()) {

err = handleThrottling(
func() error {
return txapi.PollResourceStringsDownload(
download,
time.Second,
sourceFile,
)
return txapi.PollResourceStringsDownload(download, sourceFile)
},
"",
func(msg string) { sendMessage(msg, false) },
Expand Down Expand Up @@ -534,7 +530,7 @@ func (task *FilePullTask) Run(send func(string), abort func()) {

err = handleThrottling(
func() error {
return txapi.PollTranslationDownload(download, time.Second, filePath)
return txapi.PollTranslationDownload(download, filePath)
},
"",
func(msg string) { sendMessage(msg, false) },
Expand Down
4 changes: 2 additions & 2 deletions internal/txlib/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func (task *SourceFilePushTask) Run(send func(string), abort func()) {

err = handleThrottling(
func() error {
return txapi.PollSourceUpload(sourceUpload, time.Second)
return txapi.PollSourceUpload(sourceUpload)
},
"",
func(msg string) { sendMessage(msg, false) },
Expand Down Expand Up @@ -734,7 +734,7 @@ func (task *TranslationFileTask) Run(send func(string), abort func()) {
// Polling
err = handleThrottling(
func() error {
return txapi.PollTranslationUpload(upload, time.Second)
return txapi.PollTranslationUpload(upload)
},
"",
func(msg string) { sendMessage(msg, false) },
Expand Down
15 changes: 6 additions & 9 deletions pkg/txapi/resource_strings_async_downloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package txapi
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -33,13 +33,10 @@ func CreateResourceStringsAsyncDownload(
return download, err
}

func PollResourceStringsDownload(
download *jsonapi.Resource,
duration time.Duration,
filePath string,
) error {
func PollResourceStringsDownload(download *jsonapi.Resource, filePath string) error {
backoff := getBackoff(nil)
for {
time.Sleep(duration)
time.Sleep(time.Duration(backoff()) * time.Second)
err := download.Reload()
if err != nil {
return err
Expand All @@ -53,7 +50,7 @@ func PollResourceStringsDownload(
if resp.StatusCode != 200 {
return errors.New("file download error")
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand All @@ -64,7 +61,7 @@ func PollResourceStringsDownload(
return err
}

err = ioutil.WriteFile(filePath, bodyBytes, 0644)
err = os.WriteFile(filePath, bodyBytes, 0644)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/txapi/resource_strings_async_uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ func UploadSource(
return &upload, nil
}

func PollSourceUpload(upload *jsonapi.Resource, duration time.Duration) error {
func PollSourceUpload(upload *jsonapi.Resource) error {
backoff := getBackoff(nil)
for {
time.Sleep(duration)
time.Sleep(time.Duration(backoff()) * time.Second)
err := upload.Reload()
if err != nil {
return err
Expand Down
11 changes: 6 additions & 5 deletions pkg/txapi/resource_translations_async_downloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package txapi
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -39,9 +39,10 @@ func CreateTranslationsAsyncDownload(
return download, err
}

func PollTranslationDownload(download *jsonapi.Resource, duration time.Duration, filePath string) error {
func PollTranslationDownload(download *jsonapi.Resource, filePath string) error {
backoff := getBackoff(nil)
for {
time.Sleep(duration)
time.Sleep(time.Duration(backoff()) * time.Second)
err := download.Reload()
if err != nil {
return err
Expand All @@ -57,7 +58,7 @@ func PollTranslationDownload(download *jsonapi.Resource, duration time.Duration,
if resp.StatusCode != 200 {
return errors.New("file download error")
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return err
Expand All @@ -67,7 +68,7 @@ func PollTranslationDownload(download *jsonapi.Resource, duration time.Duration,
if err != nil {
return err
}
err = ioutil.WriteFile(filePath, bodyBytes, 0644)
err = os.WriteFile(filePath, bodyBytes, 0644)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/txapi/resource_translations_async_uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ func (err *ResourceTranslationsAsyncUploadAttributes) Error() string {
return strings.Join(parts, ", ")
}

func PollTranslationUpload(
upload *jsonapi.Resource, duration time.Duration,
) error {
func PollTranslationUpload(upload *jsonapi.Resource) error {
backoff := getBackoff(nil)
for {
time.Sleep(duration)
time.Sleep(time.Duration(backoff()) * time.Second)
err := upload.Reload()
if err != nil {
return err
Expand Down
33 changes: 33 additions & 0 deletions pkg/txapi/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package txapi

/*
Return a function that returns the next item from 'pool' every time. When 'pool' runs
out, keep returning the last item forever.

backoff := getBackoff([]int{1, 2, 3})
fmt.Println(backoff())
// <<< 1
fmt.Println(backoff())
// <<< 2
fmt.Println(backoff())
// <<< 3
fmt.Println(backoff())
// <<< 3
fmt.Println(backoff())
// <<< 3
// ...
*/
func getBackoff(pool []int) func() int {
if pool == nil {
pool = []int{1, 1, 1, 2, 3, 5, 8, 13}
}
i := -1
return func() int {
i++
if i < len(pool) {
return pool[i]
} else {
return pool[len(pool)-1]
}
}
}
0