| 60 | } |
| 61 | |
| 62 | func (p *Plugin) Run() { |
| 63 | defer func() { |
| 64 | klog.Info("Stopping plugin execution") |
| 65 | close(p.resultChan) |
| 66 | p.tomb.Done() |
| 67 | }() |
| 68 | |
| 69 | runTicker := time.NewTicker(*p.config.PluginGlobalConfig.InvokeInterval) |
| 70 | defer runTicker.Stop() |
| 71 | |
| 72 | // on boot run once |
| 73 | select { |
| 74 | case <-p.tomb.Stopping(): |
| 75 | return |
| 76 | default: |
| 77 | p.runRules() |
| 78 | } |
| 79 | |
| 80 | // run every InvokeInterval |
| 81 | for { |
| 82 | select { |
| 83 | case <-runTicker.C: |
| 84 | p.runRules() |
| 85 | case <-p.tomb.Stopping(): |
| 86 | return |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // run each rule in parallel and wait for them to complete |
| 92 | func (p *Plugin) runRules() { |