Initial work on async functions

This commit is contained in:
Seif Lotfy
2016-09-14 16:11:37 -07:00
committed by Seif Lotfy
parent bf6c4b0a4a
commit b623fc27e4
30 changed files with 1986 additions and 59 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/runner"
titancommon "github.com/iron-io/worker/common"
"github.com/iron-io/worker/runner/drivers"
"github.com/satori/go.uuid"
)
@@ -31,7 +32,7 @@ func handleSpecial(c *gin.Context) {
}
}
func handleRunner(c *gin.Context) {
func handleRequest(c *gin.Context, enqueue models.Enqueue) {
if strings.HasPrefix(c.Request.URL.Path, "/v1") {
c.Status(http.StatusNotFound)
return
@@ -151,10 +152,29 @@ func handleRunner(c *gin.Context) {
Memory: el.Memory,
}
if result, err := Api.Runner.Run(c, cfg); err != nil {
log.WithError(err).Error(models.ErrRunnerRunRoute)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRunnerRunRoute))
} else {
// Request count metric
metricBaseName := "server.handleRequest." + appName + "."
runner.LogMetricCount(ctx, (metricBaseName + "requests"), 1)
metricStart := time.Now()
var err error
var result drivers.RunResult
switch el.Type {
case "async":
// TODO: Create Task
priority := int32(0)
task := &models.Task{}
task.Image = &cfg.Image
task.ID = cfg.ID
task.GroupName = cfg.AppName
task.Priority = &priority
// TODO: Push to queue
enqueue(task)
default:
if result, err = Api.Runner.Run(c, cfg); err != nil {
break
}
for k, v := range el.Headers {
c.Header(k, v[0])
}
@@ -166,6 +186,16 @@ func handleRunner(c *gin.Context) {
c.AbortWithStatus(http.StatusInternalServerError)
}
}
if err != nil {
log.WithError(err).Error(models.ErrRunnerRunRoute)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRunnerRunRoute))
}
// Execution time metric
metricElapsed := time.Since(metricStart)
runner.LogMetricTime(ctx, (metricBaseName + "time"), metricElapsed)
runner.LogMetricTime(ctx, "server.handleRunner.exec_time", metricElapsed)
return
}
}