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

Method mainLoop

pkg/devspace/sync/downstream.go:158–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156}
157
158func (d *downstream) mainLoop() error {
159 lastAmountChanges := int64(0)
160 recheckInterval := 1700
161 if !d.sync.Options.Polling {
162 recheckInterval = 500
163 }
164
165 var (
166 changeTimer time.Time
167 )
168 for {
169 select {
170 case <-d.sync.ctx.Done():
171 return nil
172 case <-time.After(time.Duration(recheckInterval) * time.Millisecond):
173 break
174 }
175
176 // Check for changes remotely
177 ctx, cancel := context.WithTimeout(d.sync.ctx, time.Minute*10)
178 changeAmount, err := d.client.ChangesCount(ctx, &remote.Empty{})
179 cancel()
180 if err != nil {
181 return errors.Wrap(err, "count changes")
182 }
183
184 // start waiting timer
185 if changeAmount.Amount > 0 && lastAmountChanges == 0 {
186 changeTimer = time.Now().Add(waitForMoreChangesTimeout)
187 }
188
189 // Compare change amount
190 if lastAmountChanges > 0 && (time.Now().After(changeTimer) || changeAmount.Amount > 25000 || changeAmount.Amount == lastAmountChanges) {
191 d.sync.fileIndex.fileMapMutex.Lock()
192 changes, err := d.collectChanges(false)
193 d.sync.fileIndex.fileMapMutex.Unlock()
194 if err != nil {
195 return errors.Wrap(err, "collect changes")
196 }
197
198 err = d.applyChanges(changes, false)
199 if err != nil {
200 return errors.Wrap(err, "apply changes")
201 }
202
203 lastAmountChanges = 0
204 changeTimer = time.Time{}
205 } else {
206 lastAmountChanges = changeAmount.Amount
207 }
208 }
209}
210
211func (d *downstream) shouldKeep(change *remote.Change) bool {
212 // Is a delete change?

Callers

nothing calls this directly

Calls 8

collectChangesMethod · 0.95
applyChangesMethod · 0.95
WithTimeoutMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
DoneMethod · 0.65
ChangesCountMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected