StartSyncFromCmd starts a new sync from command
(ctx devspacecontext.Context, selector targetselector.TargetSelector, name string, syncConfig *latest.SyncConfig, noWatch bool)
| 15 | |
| 16 | // StartSyncFromCmd starts a new sync from command |
| 17 | func StartSyncFromCmd(ctx devspacecontext.Context, selector targetselector.TargetSelector, name string, syncConfig *latest.SyncConfig, noWatch bool) error { |
| 18 | ctx, parent := ctx.WithNewTomb() |
| 19 | options := &Options{ |
| 20 | Name: name, |
| 21 | SyncConfig: syncConfig, |
| 22 | Selector: selector, |
| 23 | RestartOnError: true, |
| 24 | SyncLog: ctx.Log(), |
| 25 | |
| 26 | Verbose: ctx.Log().GetLevel() == logrus.DebugLevel, |
| 27 | } |
| 28 | |
| 29 | // Start the tomb |
| 30 | <-parent.NotifyGo(func() error { |
| 31 | // this is needed as otherwise the context |
| 32 | // is cancelled alongside the tomb |
| 33 | parent.Go(func() error { |
| 34 | <-ctx.Context().Done() |
| 35 | return nil |
| 36 | }) |
| 37 | |
| 38 | return NewController().Start(ctx, options, parent) |
| 39 | }) |
| 40 | |
| 41 | // Handle no watch |
| 42 | if noWatch { |
| 43 | select { |
| 44 | case <-parent.Dead(): |
| 45 | return parent.Err() |
| 46 | default: |
| 47 | parent.Kill(nil) |
| 48 | _ = parent.Wait() |
| 49 | return nil |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Handle interrupt |
| 54 | select { |
| 55 | case <-parent.Dead(): |
| 56 | return parent.Err() |
| 57 | case <-ctx.Context().Done(): |
| 58 | _ = parent.Wait() |
| 59 | return nil |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // StartSync starts the syncing functionality |
| 64 | func StartSync(ctx devspacecontext.Context, devPod *latest.DevPod, selector targetselector.TargetSelector, parent *tomb.Tomb) (retErr error) { |
no test coverage detected