mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
functions: hot containers (#332)
* functions: modify datastore to accomodate hot containers support * functions: protocol between functions and hot containers * functions: add hot containers clockwork * fn: add hot containers support
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/iron-io/functions/api/datastore"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
)
|
||||
|
||||
func setLogBuffer() *bytes.Buffer {
|
||||
@@ -25,8 +25,8 @@ func setLogBuffer() *bytes.Buffer {
|
||||
return &buf
|
||||
}
|
||||
|
||||
func mockTasksConduit() chan runner.TaskRequest {
|
||||
tasks := make(chan runner.TaskRequest)
|
||||
func mockTasksConduit() chan task.Request {
|
||||
tasks := make(chan task.Request)
|
||||
go func() {
|
||||
for range tasks {
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (s *Server) handleRouteCreate(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesValidationMissingImage))
|
||||
return
|
||||
}
|
||||
err = Api.Runner.EnsureImageExists(ctx, &runner.Config{
|
||||
err = Api.Runner.EnsureImageExists(ctx, &task.Config{
|
||||
Image: wroute.Route.Image,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ func handleRouteUpdate(c *gin.Context) {
|
||||
wroute.Route.Path = path.Clean(c.Param("route"))
|
||||
|
||||
if wroute.Route.Image != "" {
|
||||
err = Api.Runner.EnsureImageExists(ctx, &runner.Config{
|
||||
err = Api.Runner.EnsureImageExists(ctx, &task.Config{
|
||||
Image: wroute.Route.Image,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/common"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
@@ -167,15 +168,18 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
envVars[ToEnvName("HEADER", header)] = strings.Join(value, " ")
|
||||
}
|
||||
|
||||
cfg := &runner.Config{
|
||||
Image: found.Image,
|
||||
Timeout: 30 * time.Second,
|
||||
ID: reqID,
|
||||
AppName: appName,
|
||||
Stdout: &stdout,
|
||||
Env: envVars,
|
||||
Memory: found.Memory,
|
||||
Stdin: payload,
|
||||
cfg := &task.Config{
|
||||
AppName: appName,
|
||||
Path: found.Path,
|
||||
Env: envVars,
|
||||
Format: found.Format,
|
||||
ID: reqID,
|
||||
Image: found.Image,
|
||||
MaxConcurrency: found.MaxConcurrency,
|
||||
Memory: found.Memory,
|
||||
Stdin: payload,
|
||||
Stdout: &stdout,
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
switch found.Type {
|
||||
|
||||
@@ -13,10 +13,11 @@ import (
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func testRouterAsync(ds models.Datastore, mq models.MessageQueue, rnr *runner.Runner, tasks chan runner.TaskRequest, enqueue models.Enqueue) *gin.Engine {
|
||||
func testRouterAsync(ds models.Datastore, mq models.MessageQueue, rnr *runner.Runner, tasks chan task.Request, enqueue models.Enqueue) *gin.Engine {
|
||||
ctx := context.Background()
|
||||
s := New(ctx, ds, mq, rnr, tasks, enqueue)
|
||||
r := s.Router
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
)
|
||||
|
||||
func testRunner(t *testing.T) *runner.Runner {
|
||||
@@ -106,7 +107,7 @@ func TestRouteRunnerPost(t *testing.T) {
|
||||
func TestRouteRunnerExecution(t *testing.T) {
|
||||
buf := setLogBuffer()
|
||||
|
||||
tasks := make(chan runner.TaskRequest)
|
||||
tasks := make(chan task.Request)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/iron-io/functions/api/ifaces"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/functions/api/server/internal/routecache"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
@@ -31,7 +32,7 @@ type Server struct {
|
||||
SpecialHandlers []ifaces.SpecialHandler
|
||||
Enqueue models.Enqueue
|
||||
|
||||
tasks chan runner.TaskRequest
|
||||
tasks chan task.Request
|
||||
|
||||
mu sync.Mutex // protects hotroutes
|
||||
hotroutes map[string]*routecache.Cache
|
||||
@@ -40,7 +41,7 @@ type Server struct {
|
||||
Datastore models.Datastore
|
||||
}
|
||||
|
||||
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, r *runner.Runner, tasks chan runner.TaskRequest, enqueue models.Enqueue) *Server {
|
||||
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, r *runner.Runner, tasks chan task.Request, enqueue models.Enqueue) *Server {
|
||||
Api = &Server{
|
||||
Runner: r,
|
||||
Router: gin.New(),
|
||||
|
||||
@@ -16,12 +16,13 @@ import (
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
var tmpBolt = "/tmp/func_test_bolt.db"
|
||||
|
||||
func testRouter(ds models.Datastore, mq models.MessageQueue, rnr *runner.Runner, tasks chan runner.TaskRequest) *gin.Engine {
|
||||
func testRouter(ds models.Datastore, mq models.MessageQueue, rnr *runner.Runner, tasks chan task.Request) *gin.Engine {
|
||||
ctx := context.Background()
|
||||
s := New(ctx, ds, mq, rnr, tasks, DefaultEnqueue)
|
||||
r := s.Router
|
||||
@@ -90,7 +91,7 @@ func TestFullStack(t *testing.T) {
|
||||
ds, closeBolt := prepareBolt(t)
|
||||
defer closeBolt()
|
||||
|
||||
tasks := make(chan runner.TaskRequest)
|
||||
tasks := make(chan task.Request)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go runner.StartWorkers(ctx, testRunner(t), tasks)
|
||||
|
||||
Reference in New Issue
Block a user