Connect on run if not connected

This commit is contained in:
Evan Phoenix 2015-04-07 09:23:58 -07:00
parent 8df5d57f6d
commit 83b77e31f4
1 changed files with 9 additions and 2 deletions

View File

@ -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
} }