mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* GRPC streams end with an EOF The client should ensure that the final packet is followed by a GRPC EOF. This has the benefit of permitting the client code to clean up resources. * Don't require an entire HTTP request in RunnerCall TryExec needs a handle on an incoming ReadCloser containing the body of a request; however, everything else will already have been extracted from the HTTP request in the case of lbAgent use. (The point of this change is to simplify the interface for other uses.) * Return error from GRPC layer explicitly As per review
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package runnerpool
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
)
|
|
|
|
// Placer implements a placement strategy for calls that are load-balanced
|
|
// across runners in a pool
|
|
type Placer interface {
|
|
PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall) error
|
|
}
|
|
|
|
// RunnerPool is the abstraction for getting an ordered list of runners to try for a call
|
|
type RunnerPool interface {
|
|
Runners(call RunnerCall) ([]Runner, error)
|
|
Shutdown(context.Context) error
|
|
}
|
|
|
|
// PKIData encapsulates TLS certificate data
|
|
type PKIData struct {
|
|
Ca string
|
|
Key string
|
|
Cert string
|
|
}
|
|
|
|
// MTLSRunnerFactory represents a factory method for constructing runners using mTLS
|
|
type MTLSRunnerFactory func(addr, certCommonName string, pki *PKIData) (Runner, error)
|
|
|
|
// Runner is the interface to invoke the execution of a function call on a specific runner
|
|
type Runner interface {
|
|
TryExec(ctx context.Context, call RunnerCall) (bool, error)
|
|
Close(ctx context.Context) error
|
|
Address() string
|
|
}
|
|
|
|
// RunnerCall provides access to the necessary details of request in order for it to be
|
|
// processed by a RunnerPool
|
|
type RunnerCall interface {
|
|
SlotDeadline() time.Time
|
|
RequestBody() io.ReadCloser
|
|
ResponseWriter() http.ResponseWriter
|
|
StdErr() io.ReadWriteCloser
|
|
Model() *models.Call
|
|
}
|