(ctx context.Context, sc multisync.Client)
| 71 | } |
| 72 | |
| 73 | func (c *MultiSyncComponent) SyncAsClient(ctx context.Context, sc multisync.Client) error { |
| 74 | var currentVersion int64 |
| 75 | v, err := c.s.GetLatest(ctx) |
| 76 | if err != nil { |
| 77 | if err != sql.ErrNoRows { |
| 78 | return fmt.Errorf("failed to get latest sync version from db: %w", err) |
| 79 | } else { |
| 80 | currentVersion = 0 |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | currentVersion = v.Version |
| 85 | var hasMore = true |
| 86 | for hasMore { |
| 87 | ctxWithTimeout, cancel := context.WithTimeout(ctx, 60*time.Second) |
| 88 | resp, err := sc.Latest(ctxWithTimeout, currentVersion) |
| 89 | cancel() |
| 90 | if err != nil { |
| 91 | return fmt.Errorf("failed to sync latest version from client, current version:%d, error: %w", currentVersion, err) |
| 92 | } |
| 93 | //create local repo |
| 94 | for _, v := range resp.Data.Versions { |
| 95 | err := c.createLocalSyncVersion(ctx, v) |
| 96 | if err != nil { |
| 97 | slog.Error("failed to create database sync version", slog.Any("sync_version", v), slog.Any("error", err)) |
| 98 | continue |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | hasMore = resp.Data.HasMore |
| 103 | if len(resp.Data.Versions) > 0 { |
| 104 | currentVersion = resp.Data.Versions[len(resp.Data.Versions)-1].Version |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | syncVersions, err := c.s.GetAfterDistinct(ctx, v.Version) |
| 109 | if err != nil { |
| 110 | slog.Error("failed to find distinct sync versions", slog.Any("error", err)) |
| 111 | return err |
| 112 | } |
| 113 | for _, v := range syncVersions { |
| 114 | sv := types.SyncVersion{ |
| 115 | Version: v.Version, |
| 116 | SourceID: v.SourceID, |
| 117 | RepoPath: v.RepoPath, |
| 118 | RepoType: v.RepoType, |
| 119 | LastModifyTime: v.LastModifiedAt, |
| 120 | ChangeLog: v.ChangeLog, |
| 121 | } |
| 122 | switch v.RepoType { |
| 123 | case types.ModelRepo: |
| 124 | ctxGetModel, cancel := context.WithTimeout(ctx, 10*time.Second) |
| 125 | modelInfo, err := sc.ModelInfo(ctxGetModel, sv) |
| 126 | if err != nil { |
| 127 | slog.Error("failed to get model info from client", slog.Any("sync_version", v)) |
| 128 | continue |
| 129 | } |
| 130 | ReadMeData, err := sc.ReadMeData(ctxGetModel, sv) |
no test coverage detected