feat(cache,worker): overhaul cache layer and add generation task lease recovery
- shared/cache: add Options/L1/async/metrics/prefix decorators, multi-key ops, Redis pool tuning, and JSON readthrough metrics - worker-generate: claim tasks via DB lease + heartbeat, requeue stale queued tasks, expire dead leases with refund/cache invalidation - tenant: version article cache keys so worker recovery invalidations propagate cleanly - shared/config: expand Redis (pool/timeouts/TLS) and Generation (lease/recovery) configs with defaults Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,15 +18,28 @@ func (c *recordingCache) Get(context.Context, string) ([]byte, error) {
|
||||
return nil, sharedcache.ErrNotFound
|
||||
}
|
||||
|
||||
func (c *recordingCache) GetMulti(context.Context, []string) (map[string][]byte, error) {
|
||||
return map[string][]byte{}, nil
|
||||
}
|
||||
|
||||
func (c *recordingCache) Set(context.Context, string, []byte, time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *recordingCache) SetMulti(context.Context, []sharedcache.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *recordingCache) Delete(_ context.Context, key string) error {
|
||||
c.deletedKeys = append(c.deletedKeys, key)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *recordingCache) DeleteMany(_ context.Context, keys []string) error {
|
||||
c.deletedKeys = append(c.deletedKeys, keys...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *recordingCache) DeletePrefix(_ context.Context, prefix string) error {
|
||||
c.deletedPrefixes = append(c.deletedPrefixes, prefix)
|
||||
return nil
|
||||
|
||||
@@ -272,6 +272,7 @@ func load(path string) (*Config, error) {
|
||||
if err := resolved.Scan(&settings); err != nil {
|
||||
return nil, fmt.Errorf("scan config: %w", err)
|
||||
}
|
||||
applySharedDefaults(settings)
|
||||
|
||||
var cfg Config
|
||||
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
@@ -303,6 +304,25 @@ func load(path string) (*Config, error) {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func applySharedDefaults(settings map[string]any) {
|
||||
cacheSettings := ensureMapSetting(settings, "cache")
|
||||
if _, ok := cacheSettings["metrics_enabled"]; !ok {
|
||||
cacheSettings["metrics_enabled"] = true
|
||||
}
|
||||
}
|
||||
|
||||
func ensureMapSetting(settings map[string]any, key string) map[string]any {
|
||||
if settings == nil {
|
||||
return map[string]any{}
|
||||
}
|
||||
if existing, ok := settings[key].(map[string]any); ok {
|
||||
return existing
|
||||
}
|
||||
next := make(map[string]any)
|
||||
settings[key] = next
|
||||
return next
|
||||
}
|
||||
|
||||
func normalizeConfig(cfg *Config) {
|
||||
if cfg.Server.Port == 0 {
|
||||
cfg.Server.Port = 8090
|
||||
@@ -313,9 +333,11 @@ func normalizeConfig(cfg *Config) {
|
||||
if strings.TrimSpace(cfg.Redis.Addr) == "" {
|
||||
cfg.Redis.Addr = "localhost:6379"
|
||||
}
|
||||
sharedconfig.NormalizeRedisConfig(&cfg.Redis)
|
||||
if strings.TrimSpace(cfg.Cache.Driver) == "" {
|
||||
cfg.Cache.Driver = "redis"
|
||||
}
|
||||
sharedconfig.NormalizeCacheConfig(&cfg.Cache)
|
||||
if strings.TrimSpace(cfg.Log.Level) == "" {
|
||||
cfg.Log.Level = "info"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user