(ctx context.Context, cfg *config.Configuration)
| 204 | } |
| 205 | |
| 206 | func initializeTypeSense(ctx context.Context, cfg *config.Configuration) (*search.TypesenseClient, error) { |
| 207 | if cfg.TypeSense.Dns == "" { |
| 208 | logrus.Warn("TypeSense DNS not configured. Search functionality will be disabled.") |
| 209 | return nil, nil |
| 210 | } |
| 211 | |
| 212 | newSearch := search.NewTypesenseClient(cfg.TypeSenseKey, []string{cfg.TypeSense.Dns}) |
| 213 | |
| 214 | const maxRetries = 5 |
| 215 | var retryDelay = 2 * time.Second |
| 216 | var err error |
| 217 | |
| 218 | for i := 0; i < maxRetries; i++ { |
| 219 | if err = newSearch.EnsureCollectionsExist(ctx); err == nil { |
| 220 | if err = migrateTypeSenseSchema(ctx, newSearch); err == nil { |
| 221 | return newSearch, nil |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | logrus.Errorf("TypeSense initialization failed (attempt %d/%d): %v. Retrying in %v...", i+1, maxRetries, err, retryDelay) |
| 226 | |
| 227 | select { |
| 228 | case <-ctx.Done(): |
| 229 | return nil, ctx.Err() |
| 230 | case <-time.After(retryDelay): |
| 231 | retryDelay *= 2 |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return nil, fmt.Errorf("failed to initialize TypeSense after %d attempts: %v", maxRetries, err) |
| 236 | } |
| 237 | |
| 238 | func initializePostHog(cfg *config.Configuration) (posthog.Client, string) { |
| 239 | if cfg.TelemetryKey == "" { |
no test coverage detected