Skip to content

Commit

Permalink
fix(tgc): EOF error when network is poor. #158
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed May 17, 2023
1 parent 6d964c6 commit 2ebbf54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/internal/tgc/tgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(ctx context.Context, login bool, middlewares ...telegram.Middleware) (*
b := backoff.NewExponentialBackOff()

b.Multiplier = 1.1
b.MaxElapsedTime = 30 * time.Second
b.MaxElapsedTime = viper.GetDuration(consts.FlagReconnectTimeout)
b.Clock = _clock
return b
},
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/spf13/viper"
"go.uber.org/zap"
"path/filepath"
"strings"
"time"
)

func New() *cobra.Command {
Expand Down Expand Up @@ -53,6 +55,7 @@ func New() *cobra.Command {
cmd.PersistentFlags().IntP(consts.FlagLimit, "l", 2, "max number of concurrent tasks")

cmd.PersistentFlags().String(consts.FlagNTP, "", "ntp server host, if not set, use system time")
cmd.PersistentFlags().Duration(consts.FlagReconnectTimeout, 30*time.Second, "Telegram client reconnection backoff timeout, infinite if set to 0") // #158

// completion
_ = cmd.RegisterFlagCompletionFunc(consts.FlagNamespace, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand All @@ -66,6 +69,7 @@ func New() *cobra.Command {
_ = viper.BindPFlags(cmd.PersistentFlags())

viper.SetEnvPrefix("tdl")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()

generateCommandDocs(cmd)
Expand Down
17 changes: 9 additions & 8 deletions pkg/consts/flag.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package consts

const (
FlagProxy = "proxy"
FlagNamespace = "ns"
FlagDebug = "debug"
FlagPartSize = "size"
FlagThreads = "threads"
FlagLimit = "limit"
FlagNTP = "ntp"
FlagDlTemplate = "template"
FlagProxy = "proxy"
FlagNamespace = "ns"
FlagDebug = "debug"
FlagPartSize = "size"
FlagThreads = "threads"
FlagLimit = "limit"
FlagNTP = "ntp"
FlagReconnectTimeout = "reconnect-timeout"
FlagDlTemplate = "template"
)

0 comments on commit 2ebbf54

Please sign in to comment.