MCPcopy Index your code
hub / github.com/devspace-sh/devspace / mainLoop

Method mainLoop

pkg/devspace/sync/upstream.go:201–267  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199}
200
201func (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 }

Callers

nothing calls this directly

Calls 10

startEventsLoopMethod · 0.95
getEventsMethod · 0.95
applyChangesMethod · 0.95
closeFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
DoneMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected