| 1 | package schedule |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/carlosframework/platform/internal/hostwrite" |
| 6 | "github.com/carlosframework/platform/internal/registry" |
| 7 | "net/http" |
| 8 | ) |
| 9 | |
| 10 | // ClaimDeliverer admits the actual HTTP request after any cold wake. A timer |
| 11 | // must not register against a predecessor then wait for its own stop drain. |
| 12 | type ClaimDeliverer interface { |
| 13 | DeliverClaim(context.Context, registry.Route, *http.Request, func(context.Context) (context.Context, func(), error)) (int, error) |
| 14 | } |
| 15 | type DeliveryAdmission func(context.Context, hostwrite.Work, registry.Route, registry.Timer) (context.Context, func(), error) |
| 16 | |
| 17 | func (r *Runner) deliverClaim(ctx context.Context, rt registry.Route, t registry.Timer, req *http.Request) (int, error) { |
| 18 | d, ok := r.Deliver.(ClaimDeliverer) |
| 19 | selected, found := ctx.Value(timerWorkKey{}).(timerWork) |
| 20 | if !ok || !found || selected.work == nil || r.StartDelivery == nil { |
| 21 | return 0, hostwrite.ErrUnavailable |
| 22 | } |
| 23 | return d.DeliverClaim(ctx, rt, req, func(call context.Context) (context.Context, func(), error) { |
| 24 | return r.StartDelivery(call, selected.work, rt, t) |
| 25 | }) |
| 26 | } |
| 27 | |