mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Depend on iron-io/runner instead of iron-io/worker (#124)
This commit is contained in:
committed by
GitHub
parent
eed5422c59
commit
fbcec6bf40
@@ -1,29 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// WithLogger stores the logger.
|
||||
func WithLogger(ctx context.Context, l logrus.FieldLogger) context.Context {
|
||||
return context.WithValue(ctx, "logger", l)
|
||||
}
|
||||
|
||||
// Logger returns the structured logger.
|
||||
func Logger(ctx context.Context) logrus.FieldLogger {
|
||||
l, ok := ctx.Value("logger").(logrus.FieldLogger)
|
||||
if !ok {
|
||||
return logrus.StandardLogger()
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// Attempt at simplifying this whole logger in the context thing
|
||||
// Could even make this take a generic map, then the logger that gets returned could be used just like the stdlib too, since it's compatible
|
||||
func LoggerWithFields(ctx context.Context, fields logrus.Fields) (context.Context, logrus.FieldLogger) {
|
||||
l := Logger(ctx)
|
||||
l = l.WithFields(fields)
|
||||
ctx = WithLogger(ctx, l)
|
||||
return ctx, l
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/google/btree"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func NewMetricLogger() *MetricLogger {
|
||||
type MetricLogger struct{}
|
||||
|
||||
func (l *MetricLogger) Log(ctx context.Context, metric map[string]interface{}) {
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
log.WithFields(logrus.Fields(metric)).Info()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,11 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/worker/runner/agent"
|
||||
"github.com/iron-io/worker/runner/drivers"
|
||||
driverscommon "github.com/iron-io/worker/runner/drivers"
|
||||
"github.com/iron-io/worker/runner/drivers/docker"
|
||||
"github.com/iron-io/worker/runner/drivers/mock"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
driverscommon "github.com/iron-io/runner/drivers"
|
||||
"github.com/iron-io/runner/drivers/docker"
|
||||
"github.com/iron-io/runner/drivers/mock"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -157,7 +156,7 @@ func (r *Runner) Run(ctx context.Context, cfg *Config) (drivers.RunResult, error
|
||||
ctask := &containerTask{
|
||||
ctx: ctx,
|
||||
cfg: cfg,
|
||||
auth: &agent.ConfigAuth{},
|
||||
auth: &common.ConfigAuth{},
|
||||
canRun: make(chan bool),
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ func (r *Runner) Run(ctx context.Context, cfg *Config) (drivers.RunResult, error
|
||||
func (r Runner) EnsureImageExists(ctx context.Context, cfg *Config) error {
|
||||
ctask := &containerTask{
|
||||
cfg: cfg,
|
||||
auth: &agent.ConfigAuth{},
|
||||
auth: &common.ConfigAuth{},
|
||||
}
|
||||
|
||||
err := r.driver.EnsureImageExists(ctx, ctask)
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
|
||||
dockercli "github.com/fsouza/go-dockerclient"
|
||||
"github.com/iron-io/worker/runner/drivers"
|
||||
"github.com/iron-io/worker/runner/tasker"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
)
|
||||
|
||||
type containerTask struct {
|
||||
ctx context.Context
|
||||
auth tasker.Auther
|
||||
auth *common.ConfigAuth
|
||||
cfg *Config
|
||||
canRun chan bool
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleAppCreate(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
var wapp models.AppWrapper
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleAppDelete(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
appName := c.Param("app")
|
||||
err := Api.Datastore.RemoveApp(appName)
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleAppGet(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
appName := c.Param("app")
|
||||
app, err := Api.Datastore.GetApp(appName)
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleAppList(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
filter := &models.AppFilter{}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleAppUpdate(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
wapp := models.AppWrapper{}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"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/runner/common"
|
||||
)
|
||||
|
||||
type appResponse struct {
|
||||
@@ -45,7 +45,7 @@ func testRouter() *gin.Engine {
|
||||
r := gin.Default()
|
||||
ctx := context.Background()
|
||||
r.Use(func(c *gin.Context) {
|
||||
ctx, _ := titancommon.LoggerWithFields(ctx, extractFields(c))
|
||||
ctx, _ := common.LoggerWithFields(ctx, extractFields(c))
|
||||
c.Set("ctx", ctx)
|
||||
c.Next()
|
||||
})
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"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/runner/common"
|
||||
)
|
||||
|
||||
func handleRouteCreate(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
var wroute models.RouteWrapper
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleRouteDelete(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
appName := c.Param("app")
|
||||
routePath := c.Param("route")
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleRouteGet(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
appName := c.Param("app")
|
||||
routePath := c.Param("route")
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleRouteList(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
filter := &models.RouteFilter{}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
func handleRouteUpdate(c *gin.Context) {
|
||||
ctx := c.MustGet("ctx").(context.Context)
|
||||
log := titancommon.Logger(ctx)
|
||||
log := common.Logger(ctx)
|
||||
|
||||
var wroute models.RouteWrapper
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/common"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/worker/runner/drivers"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
"github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
|
||||
@@ -13,8 +13,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/worker/common"
|
||||
titancommon "github.com/iron-io/worker/common"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
// Would be nice to not have this is a global, but hard to pass things around to the
|
||||
@@ -139,7 +138,7 @@ func extractFields(c *gin.Context) logrus.Fields {
|
||||
|
||||
func (s *Server) Run(ctx context.Context) {
|
||||
s.Router.Use(func(c *gin.Context) {
|
||||
ctx, _ := titancommon.LoggerWithFields(ctx, extractFields(c))
|
||||
ctx, _ := common.LoggerWithFields(ctx, extractFields(c))
|
||||
c.Set("ctx", ctx)
|
||||
c.Next()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user