resolveDBFromPayload returns the DB to use: from poolCache when host is in payload, else defaultDB.
(ctx context.Context, payload []byte, defaultDB *database.DB, poolCache *hostctx.PoolCache)
| 32 | |
| 33 | // resolveDBFromPayload returns the DB to use: from poolCache when host is in payload, else defaultDB. |
| 34 | func resolveDBFromPayload(ctx context.Context, payload []byte, defaultDB *database.DB, poolCache *hostctx.PoolCache) *database.DB { |
| 35 | db := defaultDB |
| 36 | if len(payload) == 0 || poolCache == nil { |
| 37 | return db |
| 38 | } |
| 39 | var p AutomationPayload |
| 40 | if err := json.Unmarshal(payload, &p); err == nil && strings.TrimSpace(p.Host) != "" { |
| 41 | if resolved, err := poolCache.GetOrCreate(ctx, p.Host); err == nil && resolved != nil { |
| 42 | db = resolved |
| 43 | } |
| 44 | } |
| 45 | return db |
| 46 | } |
| 47 | |
| 48 | // workerTenantKey prefixes a Redis key with the context domain for multi-context isolation. |
| 49 | // Mirrors hostctx.TenantKey but works in worker context where only the host string |
no test coverage detected