Skip to content

Commit

Permalink
iter4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ex0rcist committed Jul 5, 2024
1 parent 25c9998 commit 7bdaa66
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ func (app *Agent) ParseFlags() error {
address := app.Config.Address

pflag.VarP(&address, "address", "a", "address:port for HTTP API requests") // HELP: "&"" because Set() has pointer receiver?
pflag.DurationVarP(&app.Config.PollInterval, "poll-interval", "p", app.Config.PollInterval, "interval (s) for polling stats")
pflag.DurationVarP(&app.Config.ReportInterval, "report-interval", "r", app.Config.ReportInterval, "interval (s) for polling stats")

// Task requires us to receive intervals in seconds, not duration, so we have to do it dirty
pollFlag := pflag.IntP("poll-interval", "p", durationToInt(app.Config.PollInterval), "interval (s) for polling stats")
reportFlag := pflag.IntP("report-interval", "r", durationToInt(app.Config.ReportInterval), "interval (s) for polling stats")

pflag.Parse()

app.Config.PollInterval = intToDuration(*pollFlag)
app.Config.ReportInterval = intToDuration(*reportFlag)

// because VarP gets non-pointer value, set it manually
pflag.Visit(func(f *pflag.Flag) {
switch f.Name {
Expand Down Expand Up @@ -84,7 +89,7 @@ func (app *Agent) startReporting() {
func (app *Agent) reportStats() {
log.Info().Msg("reporting stats ... ")

// agent continues polling while repor is in progress, take snapshot
// agent continues polling while report is in progress, take snapshot?
snapshot := *app.Stats

app.API.
Expand Down Expand Up @@ -122,3 +127,11 @@ func (app *Agent) reportStats() {
app.API.
Report("PollCount", snapshot.PollCount)
}

func intToDuration(s int) time.Duration {
return time.Duration(s) * time.Second
}

func durationToInt(d time.Duration) int {
return int(d.Seconds())
}

0 comments on commit 7bdaa66

Please sign in to comment.