plumb all config fields into task

the mqs are storing a models.Task, which was not incorporating all the fields
that are in a task.Config. I would very much like to merge these two things,
but expect to do this in a future restructuring as both are used widely and
not cordoned off properly (Config has a channel, stdin, stdout, stderr -- and
isn't just a 'config', so to speak, as Task is).

Since a task.Config is what is used to actually run a container, the result of
the aforementioned deficiency was #193 where tasks are improperly configured
and ran (namely, memory wrong).

async tasks can still not be hot, they will be reverted to default format.
would also like to fix this (also part of restructuring). I actually started
doing this, hence the changes to those files (the surface area of the change
is small and discourages improper future use, so I've left what I've done).

this will:

closes #193
closes #195
closes #154

removes many unused fields in models.Task, since we have not implemented
retries. priority & delay are left, even though they are not used either,
the main goal of this is to resolve #193 and both these fields are strongly
plumbed into all the mqs, so punting on those two.
This commit is contained in:
Reed Allman
2017-08-03 04:30:16 -07:00
parent 7758e4a76a
commit 6a7973e6b6
15 changed files with 115 additions and 208 deletions

View File

@@ -19,7 +19,6 @@ import (
"github.com/fnproject/fn/api/runner/common"
"github.com/fnproject/fn/api/runner/task"
"github.com/gin-gonic/gin"
"github.com/go-openapi/strfmt"
cache "github.com/patrickmn/go-cache"
)
@@ -148,8 +147,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, rout
baseVars["FN_FORMAT"] = route.Format
baseVars["APP_NAME"] = appName
baseVars["ROUTE"] = route.Path
// TODO add this back after #193 #195 (fix async RAM)
// baseVars["MEMORY_MB"] = fmt.Sprintf("%d", route.Memory)
baseVars["MEMORY_MB"] = fmt.Sprintf("%d", route.Memory)
// app config
for k, v := range app.Config {
@@ -213,26 +211,20 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, rout
}
s.Runner.Enqueue()
createdAt := strfmt.DateTime(time.Now())
newTask := &models.Task{}
newTask.Image = &cfg.Image
newTask.ID = cfg.ID
newTask.CreatedAt = createdAt
newTask.Path = route.Path
newTask.EnvVars = cfg.Env
newTask.AppName = cfg.AppName
newTask := task.TaskFromConfig(cfg)
switch route.Type {
case "async":
// TODO we should be able to do hot input to async. plumb protocol stuff
// TODO enqueue should unravel the payload?
// Read payload
pl, err := ioutil.ReadAll(cfg.Stdin)
if err != nil {
handleErrorResponse(c, models.ErrInvalidPayload)
return true
}
// Create Task
priority := int32(0)
newTask.Priority = &priority
// Add in payload
newTask.Payload = string(pl)
// Push to queue
@@ -243,7 +235,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, rout
}
log.Info("Added new task to queue")
c.JSON(http.StatusAccepted, map[string]string{"call_id": newTask.ID})
c.JSON(http.StatusAccepted, map[string]string{"call_id": cfg.ID})
default:
result, err := s.Runner.RunTrackedTask(newTask, ctx, cfg)