mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
@@ -17,6 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
ID string
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
Route *models.Route
|
Route *models.Route
|
||||||
Payload string
|
Payload string
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package runner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ func TestRunnerHello(t *testing.T) {
|
|||||||
{&models.Route{Image: "iron/hello"}, `{"name": "test"}`, "success", "Hello test!", ""},
|
{&models.Route{Image: "iron/hello"}, `{"name": "test"}`, "success", "Hello test!", ""},
|
||||||
} {
|
} {
|
||||||
runner := New(&Config{
|
runner := New(&Config{
|
||||||
|
ID: fmt.Sprintf("task-hello-%d-%d", i, time.Now().Unix()),
|
||||||
Ctx: context.Background(),
|
Ctx: context.Background(),
|
||||||
Route: test.route,
|
Route: test.route,
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
@@ -57,6 +59,7 @@ func TestRunnerError(t *testing.T) {
|
|||||||
{&models.Route{Image: "iron/error"}, `{"name": "test"}`, "error", "", "RuntimeError"},
|
{&models.Route{Image: "iron/error"}, `{"name": "test"}`, "error", "", "RuntimeError"},
|
||||||
} {
|
} {
|
||||||
runner := New(&Config{
|
runner := New(&Config{
|
||||||
|
ID: fmt.Sprintf("task-error-%d-%d", i, time.Now().Unix()),
|
||||||
Ctx: context.Background(),
|
Ctx: context.Background(),
|
||||||
Route: test.route,
|
Route: test.route,
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (t *containerTask) EnvVars() map[string]string {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *containerTask) Id() string { return "" }
|
func (t *containerTask) Id() string { return t.cfg.ID }
|
||||||
func (t *containerTask) Group() string { return "" }
|
func (t *containerTask) Group() string { return "" }
|
||||||
func (t *containerTask) Image() string { return t.cfg.Route.Image }
|
func (t *containerTask) Image() string { return t.cfg.Route.Image }
|
||||||
func (t *containerTask) Timeout() uint { return uint(t.cfg.Timeout.Seconds()) }
|
func (t *containerTask) Timeout() uint { return uint(t.cfg.Timeout.Seconds()) }
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/iron-io/functions/api/models"
|
"github.com/iron-io/functions/api/models"
|
||||||
"github.com/iron-io/functions/api/runner"
|
"github.com/iron-io/functions/api/runner"
|
||||||
|
"github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleRunner(c *gin.Context) {
|
func handleRunner(c *gin.Context) {
|
||||||
@@ -22,6 +24,11 @@ func handleRunner(c *gin.Context) {
|
|||||||
|
|
||||||
log := c.MustGet("log").(logrus.FieldLogger)
|
log := c.MustGet("log").(logrus.FieldLogger)
|
||||||
|
|
||||||
|
reqID := uuid.NewV5(uuid.Nil, fmt.Sprintf("%s%s%d", c.Request.RemoteAddr, c.Request.URL.Path, time.Now().Unix())).String()
|
||||||
|
c.Set("reqID", reqID)
|
||||||
|
|
||||||
|
log = log.WithFields(logrus.Fields{"request_id": reqID})
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
var payload []byte
|
var payload []byte
|
||||||
@@ -75,7 +82,6 @@ func handleRunner(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.WithField("routes", routes).Debug("Got routes from datastore")
|
log.WithField("routes", routes).Debug("Got routes from datastore")
|
||||||
|
|
||||||
for _, el := range routes {
|
for _, el := range routes {
|
||||||
if el.Path == route {
|
if el.Path == route {
|
||||||
run := runner.New(&runner.Config{
|
run := runner.New(&runner.Config{
|
||||||
@@ -83,6 +89,7 @@ func handleRunner(c *gin.Context) {
|
|||||||
Route: el,
|
Route: el,
|
||||||
Payload: string(payload),
|
Payload: string(payload),
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
|
ID: reqID,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := run.Run(); err != nil {
|
if err := run.Run(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user