CheckAndStore performs health checks and immediately stores the results to the configured storage if there were no errors. Checks are not performed if c.Storage is nil. If c.Storage is also a Maintainer, Maintain() will be called if Store() is successful.
()
| 99 | // is nil. If c.Storage is also a Maintainer, Maintain() |
| 100 | // will be called if Store() is successful. |
| 101 | func (c Checkup) CheckAndStore() error { |
| 102 | if c.Storage == nil { |
| 103 | return fmt.Errorf("no storage mechanism defined") |
| 104 | } |
| 105 | results, err := c.Check() |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | err = c.Storage.Store(results) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | if m, ok := c.Storage.(Maintainer); ok { |
| 116 | return m.Maintain() |
| 117 | } |
| 118 | |
| 119 | return nil |
| 120 | } |
| 121 | |
| 122 | // CheckAndStoreEvery calls CheckAndStore every interval. It returns |
| 123 | // the ticker that it's using so you can stop it when you don't want |