Skip to content

Commit

Permalink
cmd/tskagent: add --update flag
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Oct 21, 2024
1 parent 0e1882d commit ac54fe2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/tskagent/tskagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/creachadair/command"
"github.com/creachadair/flax"
Expand All @@ -24,9 +25,10 @@ import (
)

var flags struct {
Server string `flag:"server,Secret server address (required)"`
Socket string `flag:"socket,Agent socket path (required)"`
Prefix string `flag:"prefix,Secret name prefix (required)"`
Server string `flag:"server,Secret server address (required)"`
Socket string `flag:"socket,Agent socket path (required)"`
Prefix string `flag:"prefix,Secret name prefix (required)"`
Update time.Duration `flag:"update,Automatic update interval (0 means no updates)"`
}

func main() {
Expand Down Expand Up @@ -69,6 +71,16 @@ func run(env *command.Env) error {
if err := srv.Update(env.Context()); err != nil {
return fmt.Errorf("initialize agent: %w", err)
}
if flags.Update > 0 {
go func() {
for range time.NewTicker(flags.Update).C {
if err := srv.Update(env.Context()); err != nil {
log.Printf("WARNING: Update failed: %v", err)
}
}
}()
log.Printf("Enabled periodic updates (%v)", flags.Update)
}

var g taskgroup.Group
g.Run(func() {
Expand Down

0 comments on commit ac54fe2

Please sign in to comment.