Skip to content

Commit

Permalink
Merge pull request #31 from Keramblock/parametrize-server-timeout
Browse files Browse the repository at this point in the history
Add server timeout from cli
  • Loading branch information
umputun authored Sep 27, 2024
2 parents f833d25 + bbb94b5 commit 0bf3b2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ var opts struct {
Listen string `short:"l" long:"listen" env:"LISTEN" default:"localhost:8080" description:"listen on host:port"`
SecretKey string `short:"k" long:"key" env:"KEY" required:"true" description:"secret key"`
Batch bool `short:"b" long:"batch" description:"batch mode for multi-line scripts"`
Limit int `long:"limit" default:"10" description:"limit how many concurrent update can be running"`
TimeOut time.Duration `long:"timeout" default:"1m" description:"for how long update task can be running"`
UpdateDelay time.Duration `long:"update-delay" default:"1s" description:"delay between updates"`
Limit int `long:"limit" default:"10" description:"limit how many concurrent update can be running"`
TimeOut time.Duration `long:"timeout" default:"1m" description:"for how long batch update task can be running"`
UpdateDelay time.Duration `long:"update-delay" default:"1s" description:"delay between updates"`
Dbg bool `long:"dbg" env:"DEBUG" description:"show debug info"`
}

Expand Down Expand Up @@ -72,6 +72,7 @@ func main() {
Config: conf,
Runner: runner,
UpdateDelay: opts.UpdateDelay,
Timeout: opts.TimeOut,
}

if err := srv.Run(ctx); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Rest struct {
Config Config
Runner Runner
UpdateDelay time.Duration
Timeout time.Duration
}

// Config declares command loader from config for given tasks
Expand All @@ -46,7 +47,7 @@ func (s *Rest) Run(ctx context.Context) error {
Addr: s.Listen,
Handler: s.router(),
ReadHeaderTimeout: time.Second,
WriteTimeout: 30 * time.Second,
WriteTimeout: s.Timeout + 10*time.Second, // Give enough time to finish the task and respond
IdleTimeout: time.Second,
ErrorLog: log.ToStdLogger(log.Default(), "WARN"),
}
Expand Down

0 comments on commit 0bf3b2e

Please sign in to comment.