()
| 199 | } |
| 200 | |
| 201 | func (u *upstream) mainLoop() error { |
| 202 | doneChan := make(chan struct{}) |
| 203 | defer close(doneChan) |
| 204 | |
| 205 | // start collecting events |
| 206 | u.startEventsLoop(doneChan) |
| 207 | |
| 208 | for { |
| 209 | var ( |
| 210 | changes []*FileInformation |
| 211 | changeAmount = 0 |
| 212 | changeTimer time.Time |
| 213 | ) |
| 214 | |
| 215 | // gather changes |
| 216 | for { |
| 217 | select { |
| 218 | case <-u.sync.ctx.Done(): |
| 219 | return nil |
| 220 | case <-time.After(time.Millisecond * 600): |
| 221 | break |
| 222 | } |
| 223 | |
| 224 | // retrieve the newest events |
| 225 | events := u.getEvents() |
| 226 | if len(events) > 0 { |
| 227 | fileInformation, err := u.getFileInformationFromEvent(events) |
| 228 | if err != nil { |
| 229 | return errors.Wrap(err, "get file information from event") |
| 230 | } |
| 231 | |
| 232 | changes = append(changes, fileInformation...) |
| 233 | } |
| 234 | |
| 235 | // start waiting timer |
| 236 | if len(changes) > 0 && changeAmount == 0 { |
| 237 | changeTimer = time.Now().Add(waitForMoreChangesTimeout) |
| 238 | } |
| 239 | |
| 240 | // We gather changes till there are no more changes or |
| 241 | // a certain amount of changes is reached |
| 242 | if changeAmount > 0 && (time.Now().After(changeTimer) || len(changes) > 25000 || changeAmount == len(changes)) { |
| 243 | break |
| 244 | } |
| 245 | |
| 246 | changeAmount = len(changes) |
| 247 | if changeAmount == 0 && len(u.events) == 0 { |
| 248 | u.isBusyMutex.Lock() |
| 249 | if len(u.events) == 0 { |
| 250 | u.isBusy = false |
| 251 | } |
| 252 | u.isBusyMutex.Unlock() |
| 253 | } |
| 254 | |
| 255 | err := u.execCommandsAfterInitialSync() |
| 256 | if err != nil { |
| 257 | return errors.Wrap(err, "exec after initial sync") |
| 258 | } |
nothing calls this directly
no test coverage detected