Skip to content

Commit

Permalink
simple timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
astj committed Mar 17, 2017
1 parent cc48edf commit c606f87
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion check-log/lib/check-log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

"github.com/jessevdk/go-flags"
"github.com/mackerelio/checkers"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (opts *logOpts) prepare() error {

// Do the plugin
func Do() {
ckr := run(os.Args[1:])
ckr := runWithTimeout(os.Args[1:])
ckr.Name = "LOG"
ckr.Exit()
}
Expand Down Expand Up @@ -147,6 +148,21 @@ func parseArgs(args []string) (*logOpts, error) {
return opts, err
}

func runWithTimeout(args []string) *checkers.Checker {
done := make(chan *checkers.Checker, 1)
go func(args []string) {
done <- run(args)
}(args)

select {
case chr := <-done:
return chr
case <-time.After(time.Second * 120):
// timeout
}
return checkers.Unknown("timed out")
}

func run(args []string) *checkers.Checker {
opts, err := parseArgs(args)
if err != nil {
Expand Down

0 comments on commit c606f87

Please sign in to comment.