package schedule import ( "context" "github.com/carlosframework/platform/internal/hostwrite" "github.com/carlosframework/platform/internal/registry" "net/http" ) // ClaimDeliverer admits the actual HTTP request after any cold wake. A timer // must not register against a predecessor then wait for its own stop drain. type ClaimDeliverer interface { DeliverClaim(context.Context, registry.Route, *http.Request, func(context.Context) (context.Context, func(), error)) (int, error) } type DeliveryAdmission func(context.Context, hostwrite.Work, registry.Route, registry.Timer) (context.Context, func(), error) func (r *Runner) deliverClaim(ctx context.Context, rt registry.Route, t registry.Timer, req *http.Request) (int, error) { d, ok := r.Deliver.(ClaimDeliverer) selected, found := ctx.Value(timerWorkKey{}).(timerWork) if !ok || !found || selected.work == nil || r.StartDelivery == nil { return 0, hostwrite.ErrUnavailable } return d.DeliverClaim(ctx, rt, req, func(call context.Context) (context.Context, func(), error) { return r.StartDelivery(call, selected.work, rt, t) }) }