package redisactivity import ( "context" "time" "proxy-pool/internal/domain/activitypool" ) var _ activitypool.ProxyUpstreamReader = (*Adapter)(nil) // UpstreamForProxy is a Controller-only metadata lookup. It returns neither // the proxy record nor its credentials and is never used by the Gateway path. func (a *Adapter) UpstreamForProxy(ctx context.Context, proxyID string, now time.Time) (string, error) { if ctx == nil { return "", activitypool.ErrInvalidProxyLookup } if err := ctx.Err(); err != nil { return "", err } if a == nil || proxyID == "" || now.IsZero() { return "", activitypool.ErrInvalidProxyLookup } result, err := runScript(ctx, a.client, upstreamLookupScript, []string{a.keys.records}, now.UnixMilli(), proxyID) if err != nil { return "", err } var reply upstreamLookupScriptReply if err := decodeScriptResult(result, &reply); err != nil { return "", err } switch reply.Status { case scriptOK: if reply.Upstream == "" { return "", invalidScriptReply("upstream lookup reply omitted upstream") } return reply.Upstream, nil case scriptNotFound: return "", activitypool.ErrActivityNotFound case scriptInvalid: return "", activitypool.ErrInvalidProxyLookup default: return "", invalidScriptReply("unexpected upstream lookup status") } }