Skip to content

Commit

Permalink
Add timed ping to java
Browse files Browse the repository at this point in the history
  • Loading branch information
Herobone committed Feb 13, 2021
1 parent 78ed438 commit 46e2161
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions java_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"flag"
"fmt"
"github.com/Raqbit/mc-pinger"
"github.com/google/subcommands"
"github.com/itzg/go-flagsfiller"
"log"
"os"
"time"

mcpinger "github.com/Raqbit/mc-pinger"
"github.com/google/subcommands"
"github.com/itzg/go-flagsfiller"
)

type statusCmd struct {
Expand All @@ -18,6 +19,7 @@ type statusCmd struct {

RetryInterval time.Duration `usage:"if retry-limit is non-zero, status will be retried at this interval" default:"10s"`
RetryLimit int `usage:"if non-zero, failed status will be retried this many times before exiting"`
TimeOut time.Duration `usage:"if non-zero, this is the timeout the ping can take as a maximum"`
}

func (c *statusCmd) Name() string {
Expand All @@ -41,7 +43,12 @@ func (c *statusCmd) SetFlags(flags *flag.FlagSet) {
}

func (c *statusCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
pinger := mcpinger.New(c.Host, uint16(c.Port))
var pinger mcpinger.Pinger
if c.TimeOut > 0 {
pinger = mcpinger.NewTimed(c.Host, uint16(c.Port), c.TimeOut)
} else {
pinger = mcpinger.New(c.Host, uint16(c.Port))
}
if c.RetryInterval <= 0 {
c.RetryInterval = 1 * time.Second
}
Expand Down

0 comments on commit 46e2161

Please sign in to comment.