proxy-pool/internal/adapters/redisactivity/upstream_lookup.go
youfak 65aee12d51
Some checks are pending
ci / proto (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
ci / integration (push) Waiting to run
feat: wire checker observations into controller
2026-07-31 18:25:07 +08:00

46 lines
1.3 KiB
Go

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")
}
}