WIP: working on hot lambda functions.

This commit is contained in:
Travis Reeder
2017-06-29 08:00:29 -07:00
parent 26806ccafd
commit 1f3218f8dd
3 changed files with 80 additions and 14 deletions

View File

@@ -152,10 +152,10 @@ func (s *Server) loadroutes(ctx context.Context, filter models.RouteFilter) ([]*
}
// TODO: Should remove *gin.Context from these functions, should use only context.Context
func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, found *models.Route, app *models.App, route, reqID string, payload io.Reader, enqueue models.Enqueue) (ok bool) {
ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"app": appName, "route": found.Path, "image": found.Image})
func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, route *models.Route, app *models.App, path, reqID string, payload io.Reader, enqueue models.Enqueue) (ok bool) {
ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"app": appName, "route": route.Path, "image": route.Image})
params, match := matchRoute(found.Path, route)
params, match := matchRoute(route.Path, path)
if !match {
return false
}
@@ -165,7 +165,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
envVars := map[string]string{
"METHOD": c.Request.Method,
"APP_NAME": appName,
"ROUTE": found.Path,
"ROUTE": route.Path,
"REQUEST_URL": fmt.Sprintf("%v//%v%v", func() string {
if c.Request.TLS == nil {
return "http"
@@ -173,13 +173,14 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
return "https"
}(), c.Request.Host, c.Request.URL.String()),
"CALL_ID": reqID,
"FORMAT": route.Format,
}
// app config
for k, v := range app.Config {
envVars[toEnvName("", k)] = v
}
for k, v := range found.Config {
for k, v := range route.Config {
envVars[toEnvName("", k)] = v
}
@@ -195,16 +196,16 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
cfg := &task.Config{
AppName: appName,
Path: found.Path,
Path: route.Path,
Env: envVars,
Format: found.Format,
Format: route.Format,
ID: reqID,
Image: found.Image,
Memory: found.Memory,
Image: route.Image,
Memory: route.Memory,
Stdin: payload,
Stdout: &stdout,
Timeout: time.Duration(found.Timeout) * time.Second,
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
Timeout: time.Duration(route.Timeout) * time.Second,
IdleTimeout: time.Duration(route.IdleTimeout) * time.Second,
ReceivedTime: time.Now(),
Ready: make(chan struct{}),
}
@@ -223,11 +224,11 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
newTask.Image = &cfg.Image
newTask.ID = cfg.ID
newTask.CreatedAt = createdAt
newTask.Path = found.Path
newTask.Path = route.Path
newTask.EnvVars = cfg.Env
newTask.AppName = cfg.AppName
switch found.Type {
switch route.Type {
case "async":
// Read payload
pl, err := ioutil.ReadAll(cfg.Stdin)
@@ -263,7 +264,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
break
}
for k, v := range found.Headers {
for k, v := range route.Headers {
c.Header(k, v[0])
}