Run keeps the plugin worker connected and reconnects on stream failures.
(ctx context.Context)
| 164 | |
| 165 | // Run keeps the plugin worker connected and reconnects on stream failures. |
| 166 | func (w *Worker) Run(ctx context.Context) error { |
| 167 | adminAddress := pb.ServerToGrpcAddress(w.opts.AdminServer) |
| 168 | |
| 169 | for { |
| 170 | select { |
| 171 | case <-ctx.Done(): |
| 172 | return nil |
| 173 | default: |
| 174 | } |
| 175 | |
| 176 | if err := w.runOnce(ctx, adminAddress); err != nil { |
| 177 | if ctx.Err() != nil { |
| 178 | return nil |
| 179 | } |
| 180 | glog.Warningf("Plugin worker %s stream ended: %v", w.workerID, err) |
| 181 | } |
| 182 | |
| 183 | select { |
| 184 | case <-ctx.Done(): |
| 185 | return nil |
| 186 | case <-time.After(w.opts.ReconnectDelay): |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func (w *Worker) runOnce(ctx context.Context, adminAddress string) error { |
| 192 | defer w.setConnected(false) |