(ctx devspacecontext.Context, options *Options, parent *tomb.Tomb)
| 82 | } |
| 83 | |
| 84 | func (c *controller) startWithWait(ctx devspacecontext.Context, options *Options, parent *tomb.Tomb) error { |
| 85 | if ctx.IsDone() { |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | var ( |
| 90 | onInitUploadDone chan struct{} |
| 91 | onInitDownloadDone chan struct{} |
| 92 | onError = make(chan error, 1) |
| 93 | onDone = make(chan struct{}) |
| 94 | ) |
| 95 | |
| 96 | // should wait for initial sync? |
| 97 | if options.SyncConfig.WaitInitialSync == nil || *options.SyncConfig.WaitInitialSync { |
| 98 | onInitUploadDone = make(chan struct{}) |
| 99 | onInitDownloadDone = make(chan struct{}) |
| 100 | pluginErr := hook.ExecuteHooks(ctx, map[string]interface{}{ |
| 101 | "sync_config": options.SyncConfig, |
| 102 | }, hook.EventsForSingle("before:initialSync", options.Name).With("sync.beforeInitialSync")...) |
| 103 | if pluginErr != nil { |
| 104 | return pluginErr |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // start the sync |
| 109 | client, pod, err := c.startSync(ctx, options, onInitUploadDone, onInitDownloadDone, onDone, onError) |
| 110 | if err != nil { |
| 111 | pluginErr := hook.ExecuteHooks(ctx, map[string]interface{}{ |
| 112 | "sync_config": options.SyncConfig, |
| 113 | "ERROR": err, |
| 114 | }, hook.EventsForSingle("error:initialSync", options.Name).With("sync.errorInitialSync")...) |
| 115 | if pluginErr != nil { |
| 116 | return pluginErr |
| 117 | } |
| 118 | |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | // should wait for initial sync? |
| 123 | if options.SyncConfig.WaitInitialSync == nil || *options.SyncConfig.WaitInitialSync { |
| 124 | ctx.Log().Info("Waiting for initial sync to complete") |
| 125 | defer ctx.Log().Info("Initial sync completed") |
| 126 | var ( |
| 127 | uploadDone = false |
| 128 | downloadDone = false |
| 129 | ) |
| 130 | started := time.Now() |
| 131 | for { |
| 132 | select { |
| 133 | case err := <-onError: |
| 134 | pluginErr := hook.ExecuteHooks(ctx, map[string]interface{}{ |
| 135 | "sync_config": options.SyncConfig, |
| 136 | "ERROR": err, |
| 137 | }, hook.EventsForSingle("error:initialSync", options.Name).With("sync.errorInitialSync")...) |
| 138 | if pluginErr != nil { |
| 139 | return pluginErr |
| 140 | } |
| 141 | if ctx.IsDone() { |
no test coverage detected