Run starts the ingestionAssignmentTask
()
| 122 | |
| 123 | // Run starts the ingestionAssignmentTask |
| 124 | func (ia *ingestionAssignmentTask) Run() { |
| 125 | hostName, _ := os.Hostname() |
| 126 | |
| 127 | // wait random interval to avoid herd effect electing for leader on cluster reboot |
| 128 | waitSeconds := rand.Intn(5) |
| 129 | time.Sleep(time.Duration(waitSeconds) * time.Second) |
| 130 | |
| 131 | ia.logger.With( |
| 132 | "host", hostName, |
| 133 | "waitedSeconds", waitSeconds, |
| 134 | ).Info("start ingestion assignment task after waiting") |
| 135 | |
| 136 | if err := ia.leaderElection.Start(); err != nil { |
| 137 | ia.logger.With("host", hostName, "error", err.Error()).Error("failed to start leader election") |
| 138 | ia.scope.Counter("task_failed").Inc(1) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | defer func() { |
| 143 | err := ia.leaderElection.Close() |
| 144 | if err != nil { |
| 145 | ia.logger.Error(err) |
| 146 | } else { |
| 147 | ia.logger.With("host", hostName).Infof("stopped leader election") |
| 148 | } |
| 149 | }() |
| 150 | |
| 151 | ia.logger.With("host", hostName).Infof("entering ingestion assignment calculation loop") |
| 152 | ia.startIngestionAssignment(hostName) |
| 153 | ia.logger.With("host", hostName).Infof("exited ingestion assignment calculation loop") |
| 154 | } |
| 155 | |
| 156 | // Done stops the task |
| 157 | func (ia *ingestionAssignmentTask) Done() { |