Skip to content

Commit

Permalink
add flag to control context timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Apr 22, 2021
1 parent 132e369 commit 6ad656e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var appArgs = struct {
elevate *bool

throttle *int64
contextTimeout *int64
simulateOffline *bool
}{
app.Flag("json", "Enable machine-readable JSON-lines output").Hidden().Short('j').Bool(),
Expand All @@ -91,6 +92,7 @@ var appArgs = struct {
app.Flag("elevate", "Run butler as administrator").Hidden().Bool(),

app.Flag("throttle", "Use less than 'throttle' Kbps (kilobits per second) of bandwidth").Hidden().Default("-1").Int64(),
app.Flag("context-timeout", "Network operations timeout in seconds").Default("15").Int64(),
app.Flag("simulateOffline", "Simulate offline").Hidden().Default("false").Bool(),
}

Expand Down Expand Up @@ -232,6 +234,7 @@ func doMain(args []string) {
ctx.DBPath = *appArgs.dbPath
ctx.Quiet = *appArgs.quiet
ctx.Verbose = *appArgs.verbose
ctx.ContextTimeout = *appArgs.contextTimeout
ctx.JSON = *appArgs.json
ctx.CompressionAlgorithm = *appArgs.compressionAlgorithm
ctx.CompressionQuality = *appArgs.compressionQuality
Expand Down
4 changes: 3 additions & 1 deletion mansion/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Context struct {
CompressionAlgorithm string
CompressionQuality int

ContextTimeout int64

HTTPClient *http.Client
HTTPTransport *http.Transport

Expand Down Expand Up @@ -117,7 +119,7 @@ func (ctx *Context) CompressionSettings() pwr.CompressionSettings {
}

func (ctx *Context) DefaultCtx() context.Context {
defaultCtx, _ := context.WithTimeout(context.Background(), 15*time.Second)
defaultCtx, _ := context.WithTimeout(context.Background(), time.Duration(ctx.ContextTimeout)*time.Second)
return defaultCtx
}

Expand Down

0 comments on commit 6ad656e

Please sign in to comment.