mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Adds extension points for runner pools in load-balanced mode (Patch 1/2) (#851)
* adds extension points for runner pools in load-balanced mode * adds error to return values in RunnerPool and Runner interfaces
This commit is contained in:
31
api/models/runner_pool.go
Normal file
31
api/models/runner_pool.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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() 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() 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
|
||||||
|
Request() *http.Request
|
||||||
|
ResponseWriter() io.Writer
|
||||||
|
StdErr() io.ReadWriteCloser
|
||||||
|
Model() *Call
|
||||||
|
}
|
||||||
@@ -113,6 +113,7 @@ type Server struct {
|
|||||||
rootMiddlewares []fnext.Middleware
|
rootMiddlewares []fnext.Middleware
|
||||||
apiMiddlewares []fnext.Middleware
|
apiMiddlewares []fnext.Middleware
|
||||||
promExporter *prometheus.Exporter
|
promExporter *prometheus.Exporter
|
||||||
|
runnerPool models.RunnerPool
|
||||||
// Extensions can append to this list of contexts so that cancellations are properly handled.
|
// Extensions can append to this list of contexts so that cancellations are properly handled.
|
||||||
extraCtxs []context.Context
|
extraCtxs []context.Context
|
||||||
}
|
}
|
||||||
@@ -842,6 +843,12 @@ func (s *Server) Datastore() models.Datastore {
|
|||||||
return s.datastore
|
return s.datastore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRunnerPool provides an extension point for overriding
|
||||||
|
// the default runner pool implementation when running in load-balanced mode
|
||||||
|
func (s *Server) WithRunnerPool(runnerPool models.RunnerPool) {
|
||||||
|
s.runnerPool = runnerPool
|
||||||
|
}
|
||||||
|
|
||||||
// returns the unescaped ?cursor and ?perPage values
|
// returns the unescaped ?cursor and ?perPage values
|
||||||
// pageParams clamps 0 < ?perPage <= 100 and defaults to 30 if 0
|
// pageParams clamps 0 < ?perPage <= 100 and defaults to 30 if 0
|
||||||
// ignores parsing errors and falls back to defaults.
|
// ignores parsing errors and falls back to defaults.
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ type ExtServer interface {
|
|||||||
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
|
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
|
||||||
AddRouteEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route))
|
AddRouteEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route))
|
||||||
|
|
||||||
|
// WithRunnerPool overrides the default runner pool implementation when running in load-balanced mode
|
||||||
|
WithRunnerPool(runnerPool models.RunnerPool)
|
||||||
|
|
||||||
// Datastore returns the Datastore Fn is using
|
// Datastore returns the Datastore Fn is using
|
||||||
Datastore() models.Datastore
|
Datastore() models.Datastore
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user