Connect on run if not connected
This commit is contained in:
parent
8df5d57f6d
commit
83b77e31f4
11
agent.go
11
agent.go
|
@ -105,7 +105,14 @@ func (a *Agent) Test() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Run(shutdown chan struct{}) {
|
func (a *Agent) Run(shutdown chan struct{}) error {
|
||||||
|
if a.conn == nil {
|
||||||
|
err := a.Connect()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(a.Interval.Duration)
|
ticker := time.NewTicker(a.Interval.Duration)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -116,7 +123,7 @@ func (a *Agent) Run(shutdown chan struct{}) {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-shutdown:
|
case <-shutdown:
|
||||||
return
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue